_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q19000
RubyLint.VirtualMachine.after_initialize
train
def after_initialize @comments ||= {} @associations = {} @definitions = initial_definitions @constant_loader = ConstantLoader.new(:definitions => @definitions) @scopes = [@definitions] @value_stack = NestedStack.new @variable_stack = NestedStack.new @ignored_nodes = [] @visibility = :public reset_docstring_tags reset_method_type @constant_loader.bootstrap end
ruby
{ "resource": "" }
q19001
RubyLint.VirtualMachine.run
train
def run(ast) ast = [ast] unless ast.is_a?(Array) # pre-load all the built-in definitions. @constant_loader.run(ast) ast.each { |node| iterate(node) } freeze end
ruby
{ "resource": "" }
q19002
RubyLint.VirtualMachine.after_or_asgn
train
def after_or_asgn variable = variable_stack.pop.first value = value_stack.pop.first if variable and value conditional_assignment(variable, value, false) end end
ruby
{ "resource": "" }
q19003
RubyLint.VirtualMachine.after_and_asgn
train
def after_and_asgn variable = variable_stack.pop.first value = value_stack.pop.first conditional_assignment(variable, value) end
ruby
{ "resource": "" }
q19004
RubyLint.VirtualMachine.after_array
train
def after_array(node) builder = DefinitionBuilder::RubyArray.new( node, self, :values => value_stack.pop ) push_value(builder.build) end
ruby
{ "resource": "" }
q19005
RubyLint.VirtualMachine.after_hash
train
def after_hash(node) builder = DefinitionBuilder::RubyHash.new( node, self, :values => value_stack.pop ) push_value(builder.build) end
ruby
{ "resource": "" }
q19006
RubyLint.VirtualMachine.on_self
train
def on_self scope = current_scope method = scope.lookup(scope.method_call_type, 'self') push_value(method.return_value) end
ruby
{ "resource": "" }
q19007
RubyLint.VirtualMachine.on_class
train
def on_class(node) parent = nil parent_node = node.children[1] if parent_node parent = evaluate_node(parent_node) if !parent or !parent.const? # FIXME: this should use `definitions` instead. parent = current_scope.lookup(:const, 'Object') end end define_module(node, DefinitionBuilder::RubyClass, :parent => parent) end
ruby
{ "resource": "" }
q19008
RubyLint.VirtualMachine.on_block
train
def on_block(node) builder = DefinitionBuilder::RubyBlock.new(node, self) definition = builder.build associate_node(node, definition) push_scope(definition) end
ruby
{ "resource": "" }
q19009
RubyLint.VirtualMachine.on_def
train
def on_def(node) receiver = nil if node.type == :defs receiver = evaluate_node(node.children[0]) end builder = DefinitionBuilder::RubyMethod.new( node, self, :type => @method_type, :receiver => receiver, :visibility => @visibility ) definition = builder.build builder.scope.add_definition(definition) associate_node(node, definition) buffer_docstring_tags(node) if docstring_tags and docstring_tags.return_tag assign_return_value_from_tag( docstring_tags.return_tag, definition ) end push_scope(definition) end
ruby
{ "resource": "" }
q19010
RubyLint.VirtualMachine.after_def
train
def after_def previous = pop_scope current = current_scope reset_docstring_tags EXPORT_VARIABLES.each do |type| current.copy(previous, type) end end
ruby
{ "resource": "" }
q19011
RubyLint.VirtualMachine.on_send
train
def on_send(node) name = node.children[1].to_s name = SEND_MAPPING.fetch(name, name) callback = "on_send_#{name}" value_stack.add_stack execute_callback(callback, node) end
ruby
{ "resource": "" }
q19012
RubyLint.VirtualMachine.initial_definitions
train
def initial_definitions definitions = Definition::RubyObject.new( :name => 'root', :type => :root, :instance_type => :instance, :inherit_self => false ) definitions.parents = [ definitions.constant_proxy('Object', RubyLint.registry) ] definitions.define_self return definitions end
ruby
{ "resource": "" }
q19013
RubyLint.VirtualMachine.push_scope
train
def push_scope(definition) unless definition.is_a?(RubyLint::Definition::RubyObject) raise( ArgumentError, "Expected a RubyLint::Definition::RubyObject but got " \ "#{definition.class} instead" ) end @scopes << definition end
ruby
{ "resource": "" }
q19014
RubyLint.VirtualMachine.push_variable_value
train
def push_variable_value(node) return if value_stack.empty? || @ignored_nodes.include?(node) definition = definition_for_node(node) if definition value = definition.value ? definition.value : definition push_value(value) end end
ruby
{ "resource": "" }
q19015
RubyLint.VirtualMachine.assign_variable
train
def assign_variable(type, name, value, node) scope = assignment_scope(type) variable = scope.lookup(type, name) # If there's already a variable we'll just update it. if variable variable.reference_amount += 1 # `value` is not for conditional assignments as those are handled # manually. variable.value = value if value else variable = Definition::RubyObject.new( :type => type, :name => name, :value => value, :instance_type => :instance, :reference_amount => 0, :line => node.line, :column => node.column, :file => node.file ) end buffer_assignment_value(value) # Primarily used by #after_send to support variable assignments as method # call arguments. if value and !value_stack.empty? value_stack.push(variable.value) end add_variable(variable, scope) end
ruby
{ "resource": "" }
q19016
RubyLint.VirtualMachine.add_variable
train
def add_variable(variable, scope = current_scope) if variable_stack.empty? scope.add(variable.type, variable.name, variable) else variable_stack.push(variable) end end
ruby
{ "resource": "" }
q19017
RubyLint.VirtualMachine.create_primitive
train
def create_primitive(node, options = {}) builder = DefinitionBuilder::Primitive.new(node, self, options) return builder.build end
ruby
{ "resource": "" }
q19018
RubyLint.VirtualMachine.conditional_assignment
train
def conditional_assignment(variable, value, bool = true) variable.reference_amount += 1 if current_scope.has_definition?(variable.type, variable.name) == bool variable.value = value current_scope.add_definition(variable) buffer_assignment_value(variable.value) end end
ruby
{ "resource": "" }
q19019
RubyLint.VirtualMachine.definition_for_node
train
def definition_for_node(node) if node.const? and node.children[0] definition = ConstantPath.new(node).resolve(current_scope) else definition = current_scope.lookup(node.type, node.name) end definition = Definition::RubyObject.create_unknown unless definition return definition end
ruby
{ "resource": "" }
q19020
RubyLint.VirtualMachine.increment_reference_amount
train
def increment_reference_amount(node) definition = definition_for_node(node) if definition and !definition.frozen? definition.reference_amount += 1 end end
ruby
{ "resource": "" }
q19021
RubyLint.VirtualMachine.inherit_definition
train
def inherit_definition(definition, inherit) unless definition.parents.include?(inherit) definition.parents << inherit end end
ruby
{ "resource": "" }
q19022
RubyLint.VirtualMachine.buffer_docstring_tags
train
def buffer_docstring_tags(node) return unless comments[node] parser = Docstring::Parser.new tags = parser.parse(comments[node].map(&:text)) @docstring_tags = Docstring::Mapping.new(tags) end
ruby
{ "resource": "" }
q19023
RubyLint.VirtualMachine.create_unknown_with_method
train
def create_unknown_with_method(name) definition = Definition::RubyObject.create_unknown definition.send("define_#{@method_type}", name) return definition end
ruby
{ "resource": "" }
q19024
RubyLint.VirtualMachine.definitions_for_types
train
def definitions_for_types(types) definitions = [] # There are basically two type signatures: either the name(s) of a # constant or a method in the form of `#method_name`. types.each do |type| if type[0] == '#' found = create_unknown_with_method(type[1..-1]) else found = lookup_type_definition(type) end definitions << found if found end return definitions end
ruby
{ "resource": "" }
q19025
RubyLint.VirtualMachine.track_method_call
train
def track_method_call(definition, name, node) method = definition.lookup(definition.method_call_type, name) current = current_scope location = { :line => node.line, :column => node.column, :file => node.file } # Add the call to the current scope if we're dealing with a writable # method definition. if current.respond_to?(:calls) and !current.frozen? current.calls.push( MethodCallInfo.new(location.merge(:definition => method)) ) end # Add the caller to the called method, this allows for inverse lookups. unless method.frozen? method.callers.push( MethodCallInfo.new(location.merge(:definition => definition)) ) end end
ruby
{ "resource": "" }
q19026
RubyLint.DefinitionGenerator.group_constants
train
def group_constants(constants) grouped = Hash.new { |hash, key| hash[key] = [] } constants.each do |name| root = name.split('::')[0] grouped[root] << name end return grouped end
ruby
{ "resource": "" }
q19027
RubyLint.DefinitionGenerator.method_information
train
def method_information(inspected) arg_mapping = argument_mapping info = {:method => {}, :instance_method => {}} inspected.each do |type, methods| methods.each do |method| args = [] method.parameters.each_with_index do |arg, index| name = arg[1] || "arg#{index + 1}" args << {:type => arg_mapping[arg[0]], :name => name} end info[type][method.name] = args end end return info end
ruby
{ "resource": "" }
q19028
Capistrano.RvmMethods.rvm_task
train
def rvm_task(name,&block) if fetch(:rvm_require_role,nil).nil? task name, &block else task name, :roles => fetch(:rvm_require_role), &block end end
ruby
{ "resource": "" }
q19029
Capistrano.RvmMethods.rvm_user_command
train
def rvm_user_command(options={}) return '' unless rvm_type == :mixed && options[:subject_class] rvm_user_args = rvm_user.empty? ? 'none' : rvm_user.map(&:to_s).join(' ') rvm_bin = path_to_bin_rvm({ :with_ruby => true }.merge(options)) "#{rvm_bin} rvm user #{rvm_user_args} ; " end
ruby
{ "resource": "" }
q19030
Writeexcel.Chart.set_x_axis
train
def set_x_axis(params) name, encoding = encode_utf16(params[:name], params[:name_encoding]) formula = parse_series_formula(params[:name_formula]) @x_axis_name = name @x_axis_encoding = encoding @x_axis_formula = formula end
ruby
{ "resource": "" }
q19031
Writeexcel.Chart.set_y_axis
train
def set_y_axis(params) name, encoding = encode_utf16(params[:name], params[:name_encoding]) formula = parse_series_formula(params[:name_formula]) @y_axis_name = name @y_axis_encoding = encoding @y_axis_formula = formula end
ruby
{ "resource": "" }
q19032
Writeexcel.Chart.set_plotarea
train
def set_plotarea(params = {}) return if params.empty? area = @plotarea # Set the plotarea visibility. if params.has_key?(:visible) area[:visible] = params[:visible] return if area[:visible] == 0 end # TODO. could move this out of if statement. area[:bg_color_index] = 0x08 # Set the chart background colour. if params.has_key?(:color) index, rgb = get_color_indices(params[:color]) if !index.nil? area[:fg_color_index] = index area[:fg_color_rgb] = rgb area[:bg_color_index] = 0x08 area[:bg_color_rgb] = 0x000000 end end # Set the border line colour. if params.has_key?(:line_color) index, rgb = get_color_indices(params[:line_color]) if !index.nil? area[:line_color_index] = index area[:line_color_rgb] = rgb end end # Set the border line pattern. if params.has_key?(:line_pattern) pattern = get_line_pattern(params[:line_pattern]) area[:line_pattern] = pattern end # Set the border line weight. if params.has_key?(:line_weight) weight = get_line_weight(params[:line_weight]) area[:line_weight] = weight end end
ruby
{ "resource": "" }
q19033
Writeexcel.Chart.close
train
def close # :nodoc: # Ignore any data that has been written so far since it is probably # from unwanted Worksheet method calls. @data = '' # TODO. Check for charts without a series? # Store the chart BOF. store_bof(0x0020) # Store the page header store_header # Store the page footer store_footer # Store the page horizontal centering store_hcenter # Store the page vertical centering store_vcenter # Store the left margin store_margin_left # Store the right margin store_margin_right # Store the top margin store_margin_top # Store the bottom margin store_margin_bottom # Store the page setup store_setup # Store the sheet password store_password # Start of Chart specific records. # Store the FBI font records. store_fbi(*@config[:font_numbers]) store_fbi(*@config[:font_series]) store_fbi(*@config[:font_title]) store_fbi(*@config[:font_axes]) # Ignore UNITS record. # Store the Chart sub-stream. store_chart_stream # Append the sheet dimensions store_dimensions # TODO add SINDEX and NUMBER records. store_window2 unless @embedded store_eof end
ruby
{ "resource": "" }
q19034
Writeexcel.Chart.store_window2
train
def store_window2 # :nodoc: record = 0x023E # Record identifier length = 0x000A # Number of bytes to follow grbit = 0x0000 # Option flags rwTop = 0x0000 # Top visible row colLeft = 0x0000 # Leftmost visible column rgbHdr = 0x0000 # Row/col heading, grid color # The options flags that comprise grbit fDspFmla = 0 # 0 - bit fDspGrid = 0 # 1 fDspRwCol = 0 # 2 fFrozen = 0 # 3 fDspZeros = 0 # 4 fDefaultHdr = 0 # 5 fArabic = 0 # 6 fDspGuts = 0 # 7 fFrozenNoSplit = 0 # 0 - bit fSelected = selected? ? 1 : 0 # 1 fPaged = 0 # 2 fBreakPreview = 0 # 3 #<<< Perltidy ignore this. grbit = fDspFmla grbit |= fDspGrid << 1 grbit |= fDspRwCol << 2 grbit |= fFrozen << 3 grbit |= fDspZeros << 4 grbit |= fDefaultHdr << 5 grbit |= fArabic << 6 grbit |= fDspGuts << 7 grbit |= fFrozenNoSplit << 8 grbit |= fSelected << 9 grbit |= fPaged << 10 grbit |= fBreakPreview << 11 #>>> header = [record, length].pack("vv") data = [grbit, rwTop, colLeft, rgbHdr].pack("vvvV") append(header, data) end
ruby
{ "resource": "" }
q19035
Writeexcel.Chart.encode_utf16
train
def encode_utf16(str, encoding = 0) # :nodoc: # Exit if the $string isn't defined, i.e., hasn't been set by user. return [nil, nil] if str.nil? string = str.dup # Return if encoding is set, i.e., string has been manually encoded. #return ( undef, undef ) if $string == 1; ruby_19 { string = convert_to_ascii_if_ascii(string) } # Handle utf8 strings. if is_utf8?(string) string = utf8_to_16be(string) encoding = 1 end # Chart strings are limited to 255 characters. limit = encoding != 0 ? 255 * 2 : 255 if string.bytesize >= limit # truncate the string and raise a warning. string = string[0, limit] end [string, encoding] end
ruby
{ "resource": "" }
q19036
Writeexcel.Chart.get_color_indices
train
def get_color_indices(color) # :nodoc: invalid = 0x7FFF # return from Colors#get_color when color is invalid index = Colors.new.get_color(color) index = invalid if color.respond_to?(:coerce) && (color < 8 || color > 63) if index == invalid [nil, nil] else [index, get_color_rbg(index)] end end
ruby
{ "resource": "" }
q19037
Writeexcel.Chart.get_line_pattern
train
def get_line_pattern(value) # :nodoc: value = value.downcase if value.respond_to?(:to_str) default = 0 patterns = { 0 => 5, 1 => 0, 2 => 1, 3 => 2, 4 => 3, 5 => 4, 6 => 7, 7 => 6, 8 => 8, 'solid' => 0, 'dash' => 1, 'dot' => 2, 'dash-dot' => 3, 'dash-dot-dot' => 4, 'none' => 5, 'dark-gray' => 6, 'medium-gray' => 7, 'light-gray' => 8, } if patterns.has_key?(value) patterns[value] else default end end
ruby
{ "resource": "" }
q19038
Writeexcel.Chart.get_line_weight
train
def get_line_weight(value) # :nodoc: value = value.downcase if value.respond_to?(:to_str) default = 0 weights = { 1 => -1, 2 => 0, 3 => 1, 4 => 2, 'hairline' => -1, 'narrow' => 0, 'medium' => 1, 'wide' => 2, } if weights.has_key?(value) weights[value] else default end end
ruby
{ "resource": "" }
q19039
Writeexcel.Chart.store_chart_stream
train
def store_chart_stream # :nodoc: store_chart(*@config[:chart]) store_begin # Store the chart SCL record. store_plotgrowth if @chartarea[:visible] != 0 store_chartarea_frame_stream end # Store SERIES stream for each series. index = 0 @series.each do |series| store_series_stream( :index => index, :value_formula => series[:values][0], :value_count => series[:values][1], :category_count => series[:categories][1], :category_formula => series[:categories][0], :name => series[:name], :name_encoding => series[:name_encoding], :name_formula => series[:name_formula] ) index += 1 end store_shtprops # Write the TEXT streams. (5..6).each do |font_index| store_defaulttext store_series_text_stream(font_index) end store_axesused(1) store_axisparent_stream if !@title_name.nil? || !@title_formula.nil? store_title_text_stream end store_end end
ruby
{ "resource": "" }
q19040
Writeexcel.Chart.store_series_stream
train
def store_series_stream(params) # :nodoc: name_type = _formula_type_from_param(2, 1, params, :name_formula) value_type = _formula_type_from_param(2, 0, params, :value_formula) category_type = _formula_type_from_param(2, 0, params, :category_formula) store_series(params[:value_count], params[:category_count]) store_begin # Store the Series name AI record. store_ai(0, name_type, params[:name_formula]) unless params[:name].nil? store_seriestext(params[:name], params[:name_encoding]) end store_ai(1, value_type, params[:value_formula]) store_ai(2, category_type, params[:category_formula]) store_ai(3, 1, '' ) store_dataformat_stream(params[:index]) store_sertocrt store_end end
ruby
{ "resource": "" }
q19041
Writeexcel.Chart.store_x_axis_text_stream
train
def store_x_axis_text_stream # :nodoc: formula = @x_axis_formula.nil? ? '' : @x_axis_formula ai_type = _formula_type(2, 1, formula) store_text(*@config[:x_axis_text]) store_begin store_pos(*@config[:x_axis_text_pos]) store_fontx(8) store_ai(0, ai_type, formula) unless @x_axis_name.nil? store_seriestext(@x_axis_name, @x_axis_encoding) end store_objectlink(3) store_end end
ruby
{ "resource": "" }
q19042
Writeexcel.Chart.store_axisparent_stream
train
def store_axisparent_stream # :nodoc: store_axisparent(*@config[:axisparent]) store_begin store_pos(*@config[:axisparent_pos]) store_axis_category_stream store_axis_values_stream if !@x_axis_name.nil? || !@x_axis_formula.nil? store_x_axis_text_stream end if !@y_axis_name.nil? || !@y_axis_formula.nil? store_y_axis_text_stream end if @plotarea[:visible] != 0 store_plotarea store_plotarea_frame_stream end store_chartformat_stream store_end end
ruby
{ "resource": "" }
q19043
Writeexcel.Chart.store_ai
train
def store_ai(id, type, formula, format_index = 0) # :nodoc: formula = '' if formula == [""] record = 0x1051 # Record identifier. length = 0x0008 # Number of bytes to follow. # id # Link index. # type # Reference type. # formula # Pre-parsed formula. # format_index # Num format index. grbit = 0x0000 # Option flags. ruby_19 { formula = convert_to_ascii_if_ascii(formula) } formula_length = formula.bytesize length += formula_length header = [record, length].pack('vv') data = [id].pack('C') data += [type].pack('C') data += [grbit].pack('v') data += [format_index].pack('v') data += [formula_length].pack('v') if formula.respond_to?(:to_array) data += ruby_18 { formula[0] } || ruby_19 { formula[0].encode('BINARY') } else data += ruby_18 { formula unless formula.nil? } || ruby_19 { formula.encode('BINARY') unless formula.nil? } end append(header, data) end
ruby
{ "resource": "" }
q19044
Writeexcel.Chart.store_areaformat
train
def store_areaformat(rgbFore, rgbBack, pattern, grbit, indexFore, indexBack) # :nodoc: record = 0x100A # Record identifier. length = 0x0010 # Number of bytes to follow. # rgbFore # Foreground RGB colour. # rgbBack # Background RGB colour. # pattern # Pattern. # grbit # Option flags. # indexFore # Index to Foreground colour. # indexBack # Index to Background colour. header = [record, length].pack('vv') data = [rgbFore].pack('V') data += [rgbBack].pack('V') data += [pattern].pack('v') data += [grbit].pack('v') data += [indexFore].pack('v') data += [indexBack].pack('v') append(header, data) end
ruby
{ "resource": "" }
q19045
Writeexcel.Chart.store_axcext
train
def store_axcext # :nodoc: record = 0x1062 # Record identifier. length = 0x0012 # Number of bytes to follow. catMin = 0x0000 # Minimum category on axis. catMax = 0x0000 # Maximum category on axis. catMajor = 0x0001 # Value of major unit. unitMajor = 0x0000 # Units of major unit. catMinor = 0x0001 # Value of minor unit. unitMinor = 0x0000 # Units of minor unit. unitBase = 0x0000 # Base unit of axis. catCrossDate = 0x0000 # Crossing point. grbit = 0x00EF # Option flags. store_simple(record, length, catMin, catMax, catMajor, unitMajor, catMinor, unitMinor, unitBase, catCrossDate, grbit) end
ruby
{ "resource": "" }
q19046
Writeexcel.Chart.store_axis
train
def store_axis(type) # :nodoc: record = 0x101D # Record identifier. length = 0x0012 # Number of bytes to follow. # type # Axis type. reserved1 = 0x00000000 # Reserved. reserved2 = 0x00000000 # Reserved. reserved3 = 0x00000000 # Reserved. reserved4 = 0x00000000 # Reserved. header = [record, length].pack('vv') data = [type].pack('v') data += [reserved1].pack('V') data += [reserved2].pack('V') data += [reserved3].pack('V') data += [reserved4].pack('V') append(header, data) end
ruby
{ "resource": "" }
q19047
Writeexcel.Chart.store_axisparent
train
def store_axisparent(iax, x, y, dx, dy) # :nodoc: record = 0x1041 # Record identifier. length = 0x0012 # Number of bytes to follow. # iax # Axis index. # x # X-coord. # y # Y-coord. # dx # Length of x axis. # dy # Length of y axis. header = [record, length].pack('vv') data = [iax].pack('v') data += [x].pack('V') data += [y].pack('V') data += [dx].pack('V') data += [dy].pack('V') append(header, data) end
ruby
{ "resource": "" }
q19048
Writeexcel.Chart.store_catserrange
train
def store_catserrange # :nodoc: record = 0x1020 # Record identifier. length = 0x0008 # Number of bytes to follow. catCross = 0x0001 # Value/category crossing. catLabel = 0x0001 # Frequency of labels. catMark = 0x0001 # Frequency of ticks. grbit = 0x0001 # Option flags. store_simple(record, length, catCross, catLabel, catMark, grbit) end
ruby
{ "resource": "" }
q19049
Writeexcel.Chart.store_chartformat
train
def store_chartformat(grbit = 0) # :nodoc: record = 0x1014 # Record identifier. length = 0x0014 # Number of bytes to follow. reserved1 = 0x00000000 # Reserved. reserved2 = 0x00000000 # Reserved. reserved3 = 0x00000000 # Reserved. reserved4 = 0x00000000 # Reserved. # grbit # Option flags. icrt = 0x0000 # Drawing order. header = [record, length].pack('vv') data = [reserved1].pack('V') data += [reserved2].pack('V') data += [reserved3].pack('V') data += [reserved4].pack('V') data += [grbit].pack('v') data += [icrt].pack('v') append(header, data) end
ruby
{ "resource": "" }
q19050
Writeexcel.Chart.store_dataformat
train
def store_dataformat(series_index, series_number, point_number) # :nodoc: record = 0x1006 # Record identifier. length = 0x0008 # Number of bytes to follow. # series_index # Series index. # series_number # Series number. (Same as index). # point_number # Point number. grbit = 0x0000 # Format flags. store_simple(record, length, point_number, series_index, series_number, grbit) end
ruby
{ "resource": "" }
q19051
Writeexcel.Chart.store_fbi
train
def store_fbi(index, height, width_basis, height_basis, scale_basis) # :nodoc: record = 0x1060 # Record identifier. length = 0x000A # Number of bytes to follow. # index # Font index. height = height * 20 # Default font height in twips. # width_basis # Width basis, in twips. # height_basis # Height basis, in twips. # scale_basis # Scale by chart area or plot area. store_simple(record, length, width_basis, height_basis, height, scale_basis, index) end
ruby
{ "resource": "" }
q19052
Writeexcel.Chart.store_frame
train
def store_frame(frame_type, grbit) # :nodoc: record = 0x1032 # Record identifier. length = 0x0004 # Number of bytes to follow. # frame_type # Frame type. # grbit # Option flags. store_simple(record, length, frame_type, grbit) end
ruby
{ "resource": "" }
q19053
Writeexcel.Chart.store_legend
train
def store_legend(x, y, width, height, wType, wSpacing, grbit) # :nodoc: record = 0x1015 # Record identifier. length = 0x0014 # Number of bytes to follow. # x # X-position. # y # Y-position. # width # Width. # height # Height. # wType # Type. # wSpacing # Spacing. # grbit # Option flags. header = [record, length].pack('vv') data = [x].pack('V') data += [y].pack('V') data += [width].pack('V') data += [height].pack('V') data += [wType].pack('C') data += [wSpacing].pack('C') data += [grbit].pack('v') append(header, data) end
ruby
{ "resource": "" }
q19054
Writeexcel.Chart.store_lineformat
train
def store_lineformat(rgb, lns, we, grbit, index) # :nodoc: record = 0x1007 # Record identifier. length = 0x000C # Number of bytes to follow. # rgb # Line RGB colour. # lns # Line pattern. # we # Line weight. # grbit # Option flags. # index # Index to colour of line. header = [record, length].pack('vv') data = [rgb].pack('V') data += [lns].pack('v') data += [we].pack('v') data += [grbit].pack('v') data += [index].pack('v') append(header, data) end
ruby
{ "resource": "" }
q19055
Writeexcel.Chart.store_markerformat
train
def store_markerformat(rgbFore, rgbBack, marker, grbit, icvFore, icvBack, miSize)# :nodoc: record = 0x1009 # Record identifier. length = 0x0014 # Number of bytes to follow. # rgbFore # Foreground RGB color. # rgbBack # Background RGB color. # marker # Type of marker. # grbit # Format flags. # icvFore # Color index marker border. # icvBack # Color index marker fill. # miSize # Size of line markers. header = [record, length].pack('vv') data = [rgbFore].pack('V') data += [rgbBack].pack('V') data += [marker].pack('v') data += [grbit].pack('v') data += [icvFore].pack('v') data += [icvBack].pack('v') data += [miSize].pack('V') append(header, data) end
ruby
{ "resource": "" }
q19056
Writeexcel.Chart.store_objectlink
train
def store_objectlink(link_type) # :nodoc: record = 0x1027 # Record identifier. length = 0x0006 # Number of bytes to follow. # link_type # Object text link type. link_index1 = 0x0000 # Link index 1. link_index2 = 0x0000 # Link index 2. store_simple(record, length, link_type, link_index1, link_index2) end
ruby
{ "resource": "" }
q19057
Writeexcel.Chart.store_plotgrowth
train
def store_plotgrowth # :nodoc: record = 0x1064 # Record identifier. length = 0x0008 # Number of bytes to follow. dx_plot = 0x00010000 # Horz growth for font scale. dy_plot = 0x00010000 # Vert growth for font scale. header = [record, length].pack('vv') data = [dx_plot].pack('V') data += [dy_plot].pack('V') append(header, data) end
ruby
{ "resource": "" }
q19058
Writeexcel.Chart.store_pos
train
def store_pos(mdTopLt, mdBotRt, x1, y1, x2, y2) # :nodoc: record = 0x104F # Record identifier. length = 0x0014 # Number of bytes to follow. # mdTopLt # Top left. # mdBotRt # Bottom right. # x1 # X coordinate. # y1 # Y coordinate. # x2 # Width. # y2 # Height. header = [record, length].pack('vv') data = [mdTopLt].pack('v') data += [mdBotRt].pack('v') data += [x1].pack('V') data += [y1].pack('V') data += [x2].pack('V') data += [y2].pack('V') append(header, data) end
ruby
{ "resource": "" }
q19059
Writeexcel.Chart.store_serauxtrend
train
def store_serauxtrend(reg_type, poly_order, equation, r_squared) # :nodoc: record = 0x104B # Record identifier. length = 0x001C # Number of bytes to follow. # reg_type # Regression type. # poly_order # Polynomial order. # equation # Display equation. # r_squared # Display R-squared. # intercept # Forced intercept. # forecast # Forecast forward. # backcast # Forecast backward. # TODO. When supported, intercept needs to be NAN if not used. # Also need to reverse doubles. intercept = ['FFFFFFFF0001FFFF'].pack('H*') forecast = ['0000000000000000'].pack('H*') backcast = ['0000000000000000'].pack('H*') header = [record, length].pack('vv') data = [reg_type].pack('C') data += [poly_order].pack('C') data += intercept data += [equation].pack('C') data += [r_squared].pack('C') data += forecast data += backcast append(header, data) end
ruby
{ "resource": "" }
q19060
Writeexcel.Chart.store_series
train
def store_series(category_count, value_count) # :nodoc: record = 0x1003 # Record identifier. length = 0x000C # Number of bytes to follow. category_type = 0x0001 # Type: category. value_type = 0x0001 # Type: value. # category_count # Num of categories. # value_count # Num of values. bubble_type = 0x0001 # Type: bubble. bubble_count = 0x0000 # Num of bubble values. store_simple(record, length, category_type, value_type, category_count, value_count, bubble_type, bubble_count) end
ruby
{ "resource": "" }
q19061
Writeexcel.Chart.store_seriestext
train
def store_seriestext(str, encoding) # :nodoc: ruby_19 { str = convert_to_ascii_if_ascii(str) } record = 0x100D # Record identifier. length = 0x0000 # Number of bytes to follow. id = 0x0000 # Text id. # str # Text. # encoding # String encoding. cch = str.bytesize # String length. encoding ||= 0 # Character length is num of chars not num of bytes cch /= 2 if encoding != 0 # Change the UTF-16 name from BE to LE str = str.unpack('v*').pack('n*') if encoding != 0 length = 4 + str.bytesize header = [record, length].pack('vv') data = [id].pack('v') data += [cch].pack('C') data += [encoding].pack('C') append(header, data, str) end
ruby
{ "resource": "" }
q19062
Writeexcel.Chart.store_shtprops
train
def store_shtprops # :nodoc: record = 0x1044 # Record identifier. length = 0x0004 # Number of bytes to follow. grbit = 0x000E # Option flags. empty_cells = 0x0000 # Empty cell handling. grbit = 0x000A if @embedded store_simple(record, length, grbit, empty_cells) end
ruby
{ "resource": "" }
q19063
Writeexcel.Chart.store_tick
train
def store_tick # :nodoc: record = 0x101E # Record identifier. length = 0x001E # Number of bytes to follow. tktMajor = 0x02 # Type of major tick mark. tktMinor = 0x00 # Type of minor tick mark. tlt = 0x03 # Tick label position. wBkgMode = 0x01 # Background mode. rgb = 0x00000000 # Tick-label RGB colour. reserved1 = 0x00000000 # Reserved. reserved2 = 0x00000000 # Reserved. reserved3 = 0x00000000 # Reserved. reserved4 = 0x00000000 # Reserved. grbit = 0x0023 # Option flags. index = 0x004D # Colour index. reserved5 = 0x0000 # Reserved. header = [record, length].pack('vv') data = [tktMajor].pack('C') data += [tktMinor].pack('C') data += [tlt].pack('C') data += [wBkgMode].pack('C') data += [rgb].pack('V') data += [reserved1].pack('V') data += [reserved2].pack('V') data += [reserved3].pack('V') data += [reserved4].pack('V') data += [grbit].pack('v') data += [index].pack('v') data += [reserved5].pack('v') append(header, data) end
ruby
{ "resource": "" }
q19064
Writeexcel.Chart.store_valuerange
train
def store_valuerange # :nodoc: record = 0x101F # Record identifier. length = 0x002A # Number of bytes to follow. numMin = 0x00000000 # Minimum value on axis. numMax = 0x00000000 # Maximum value on axis. numMajor = 0x00000000 # Value of major increment. numMinor = 0x00000000 # Value of minor increment. numCross = 0x00000000 # Value where category axis crosses. grbit = 0x011F # Format flags. # TODO. Reverse doubles when they are handled. header = [record, length].pack('vv') data = [numMin].pack('d') data += [numMax].pack('d') data += [numMajor].pack('d') data += [numMinor].pack('d') data += [numCross].pack('d') data += [grbit].pack('v') append(header, data) end
ruby
{ "resource": "" }
q19065
Writeexcel.Formula.parse_formula
train
def parse_formula(formula, byte_stream = false) # Build the parse tree for the formula tokens = reverse(parse(formula)) # Add a volatile token if the formula contains a volatile function. # This must be the first token in the list # tokens.unshift('_vol') if check_volatile(tokens) != 0 # The return value depends on which Worksheet.pm method is the caller unless byte_stream # Parse formula to see if it throws any errors and then # return raw tokens to Worksheet::store_formula() # parse_tokens(tokens) tokens else # Return byte stream to Worksheet::write_formula() parse_tokens(tokens) end end
ruby
{ "resource": "" }
q19066
Writeexcel.Formula.parse_tokens
train
def parse_tokens(tokens) parse_str = '' last_type = '' modifier = '' num_args = 0 _class = 0 _classary = [1] args = tokens.dup # A note about the class modifiers used below. In general the class, # "reference" or "value", of a function is applied to all of its operands. # However, in certain circumstances the operands can have mixed classes, # e.g. =VLOOKUP with external references. These will eventually be dealt # with by the parser. However, as a workaround the class type of a token # can be changed via the repeat_formula interface. Thus, a _ref2d token can # be changed by the user to _ref2dA or _ref2dR to change its token class. # while (!args.empty?) token = args.shift if (token == '_arg') num_args = args.shift elsif (token == '_class') token = args.shift _class = @functions[token][2] # If _class is undef then it means that the function isn't valid. exit "Unknown function #{token}() in formula\n" if _class.nil? _classary.push(_class) elsif (token == '_vol') parse_str += convert_volatile() elsif (token == 'ptgBool') token = args.shift parse_str += convert_bool(token) elsif (token == '_num') token = args.shift parse_str += convert_number(token) elsif (token == '_str') token = args.shift parse_str += convert_string(token) elsif (token =~ /^_ref2d/) modifier = token.sub(/_ref2d/, '') _class = _classary[-1] _class = 0 if modifier == 'R' _class = 1 if modifier == 'V' token = args.shift parse_str += convert_ref2d(token, _class) elsif (token =~ /^_ref3d/) modifier = token.sub(/_ref3d/,'') _class = _classary[-1] _class = 0 if modifier == 'R' _class = 1 if modifier == 'V' token = args.shift parse_str += convert_ref3d(token, _class) elsif (token =~ /^_range2d/) modifier = token.sub(/_range2d/,'') _class = _classary[-1] _class = 0 if modifier == 'R' _class = 1 if modifier == 'V' token = args.shift parse_str += convert_range2d(token, _class) elsif (token =~ /^_range3d/) modifier = token.sub(/_range3d/,'') _class = _classary[-1] _class = 0 if modifier == 'R' _class = 1 if modifier == 'V' token = args.shift parse_str += convert_range3d(token, _class) elsif (token =~ /^_name/) modifier = token.sub(/_name/, '') _class = _classary[-1] _class = 0 if modifier == 'R' _class = 1 if modifier == 'V' token = args.shift parse_str += convert_name(token, _class) elsif (token == '_func') token = args.shift parse_str += convert_function(token, num_args.to_i) _classary.pop num_args = 0 # Reset after use elsif @ptg[token] parse_str += [@ptg[token]].pack("C") else # Unrecognised token return nil end end parse_str end
ruby
{ "resource": "" }
q19067
Writeexcel.Formula.convert_number
train
def convert_number(num) # Integer in the range 0..2**16-1 if ((num =~ /^\d+$/) && (num.to_i <= 65535)) return [@ptg['ptgInt'], num.to_i].pack("Cv") else # A float num = [num.to_f].pack("d") num.reverse! if @byte_order return [@ptg['ptgNum']].pack("C") + num end end
ruby
{ "resource": "" }
q19068
Writeexcel.Formula.convert_string
train
def convert_string(str) ruby_19 { str = convert_to_ascii_if_ascii(str) } encoding = 0 str.sub!(/^"/,'') # Remove leading " str.sub!(/"$/,'') # Remove trailing " str.gsub!(/""/,'"') # Substitute Excel's escaped double quote "" for " # number of characters in str length = ruby_18 { str.gsub(/[^\WA-Za-z_\d]/, ' ').length } || ruby_19 { str.length } # Handle utf8 strings if is_utf8?(str) str = utf8_to_16le(str) ruby_19 { str.force_encoding('BINARY') } encoding = 1 end exit "String in formula has more than 255 chars\n" if length > 255 [@ptg['ptgStr'], length, encoding].pack("CCC") + str end
ruby
{ "resource": "" }
q19069
Writeexcel.Formula.convert_function
train
def convert_function(token, num_args) exit "Unknown function #{token}() in formula\n" if @functions[token][0].nil? args = @functions[token][1] # Fixed number of args eg. TIME($i,$j,$k). if (args >= 0) # Check that the number of args is valid. if (args != num_args) raise "Incorrect number of arguments for #{token}() in formula\n" else return [@ptg['ptgFuncV'], @functions[token][0]].pack("Cv") end end # Variable number of args eg. SUM(i,j,k, ..). if (args == -1) return [@ptg['ptgFuncVarV'], num_args, @functions[token][0]].pack("CCv") end end
ruby
{ "resource": "" }
q19070
Writeexcel.Formula.convert_name
train
def convert_name(name, _class) name_index = get_name_index(name) # The ptg value depends on the class of the ptg. if _class == 0 ptgName = @ptg['ptgName'] elsif _class == 1 ptgName = @ptg['ptgNameV'] elsif _class == 2 ptgName = @ptg['ptgNameA'] end [ptgName, name_index].pack('CV') end
ruby
{ "resource": "" }
q19071
Writeexcel.Worksheet.close
train
def close #:nodoc: ################################################ # Prepend in reverse order!! # # Prepend the sheet dimensions store_dimensions # Prepend the autofilter filters. store_autofilters # Prepend the sheet autofilter info. store_autofilterinfo # Prepend the sheet filtermode record. store_filtermode # Prepend the COLINFO records if they exist @colinfo.reverse.each do |colinfo| store_colinfo(colinfo) end # Prepend the DEFCOLWIDTH record store_defcol # Prepend the sheet password store_password # Prepend the sheet protection store_protect store_obj_protect # Prepend the page setup store_setup # Prepend the bottom margin store_margin_bottom # Prepend the top margin store_margin_top # Prepend the right margin store_margin_right # Prepend the left margin store_margin_left # Prepend the page vertical centering store_vcenter # Prepend the page horizontal centering store_hcenter # Prepend the page footer store_footer # Prepend the page header store_header # Prepend the vertical page breaks store_vbreak # Prepend the horizontal page breaks store_hbreak # Prepend WSBOOL store_wsbool # Prepend the default row height. store_defrow # Prepend GUTS store_guts # Prepend GRIDSET store_gridset # Prepend PRINTGRIDLINES store_print_gridlines # Prepend PRINTHEADERS store_print_headers # # End of prepend. Read upwards from here. ################################################ # Append store_table store_images store_charts store_filters store_comments store_window2 store_page_view store_zoom store_panes(*@panes) if @panes && !@panes.empty? store_selection(*@selection) store_validation_count store_validations store_tab_color store_eof # Prepend the BOF and INDEX records store_index store_bof(0x0010) end
ruby
{ "resource": "" }
q19072
Writeexcel.Worksheet.hide
train
def hide @hidden = true # A hidden worksheet shouldn't be active or selected. @selected = false @workbook.worksheets.activesheet = @workbook.worksheets.first @workbook.worksheets.firstsheet = @workbook.worksheets.first end
ruby
{ "resource": "" }
q19073
Writeexcel.Worksheet.set_tab_color
train
def set_tab_color(color) color = Colors.new.get_color(color) color = 0 if color == 0x7FFF # Default color. @tab_color = color end
ruby
{ "resource": "" }
q19074
Writeexcel.Worksheet.position_object
train
def position_object(col_start, row_start, x1, y1, width, height) #:nodoc: # col_start; # Col containing upper left corner of object # x1; # Distance to left side of object # row_start; # Row containing top left corner of object # y1; # Distance to top of object # col_end; # Col containing lower right corner of object # x2; # Distance to right side of object # row_end; # Row containing bottom right corner of object # y2; # Distance to bottom of object # width; # Width of image frame # height; # Height of image frame # Adjust start column for offsets that are greater than the col width x1, col_start = adjust_col_position(x1, col_start) # Adjust start row for offsets that are greater than the row height y1, row_start = adjust_row_position(y1, row_start) # Initialise end cell to the same as the start cell col_end = col_start row_end = row_start width += x1 height += y1 # Subtract the underlying cell widths to find the end cell of the image width, col_end = adjust_col_position(width, col_end) # Subtract the underlying cell heights to find the end cell of the image height, row_end = adjust_row_position(height, row_end) # Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell # with zero eight or width. # return if size_col(col_start) == 0 return if size_col(col_end) == 0 return if size_row(row_start) == 0 return if size_row(row_end) == 0 # Convert the pixel values to the percentage value expected by Excel x1 = 1024.0 * x1 / size_col(col_start) y1 = 256.0 * y1 / size_row(row_start) x2 = 1024.0 * width / size_col(col_end) y2 = 256.0 * height / size_row(row_end) # Simulate ceil() without calling POSIX::ceil(). x1 = (x1 +0.5).to_i y1 = (y1 +0.5).to_i x2 = (x2 +0.5).to_i y2 = (y2 +0.5).to_i [ col_start, x1, row_start, y1, col_end, x2, row_end, y2 ] end
ruby
{ "resource": "" }
q19075
Writeexcel.Worksheet.store_mso_sp_container
train
def store_mso_sp_container(length) #:nodoc: type = 0xF004 version = 15 instance = 0 data = '' add_mso_generic(type, version, instance, data, length) end
ruby
{ "resource": "" }
q19076
Writeexcel.Worksheet.store_mso_sp
train
def store_mso_sp(instance, spid, options) #:nodoc: type = 0xF00A version = 2 data = '' length = 8 data = [spid, options].pack('VV') add_mso_generic(type, version, instance, data, length) end
ruby
{ "resource": "" }
q19077
Writeexcel.Worksheet.store_mso_client_data
train
def store_mso_client_data #:nodoc: type = 0xF011 version = 0 instance = 0 data = '' length = 0 add_mso_generic(type, version, instance, data, length) end
ruby
{ "resource": "" }
q19078
Writeexcel.Worksheet.boundsheet
train
def boundsheet #:nodoc: hidden = self.hidden? ? 1 : 0 encoding = self.is_name_utf16be? ? 1 : 0 record = 0x0085 # Record identifier length = 0x08 + @name.bytesize # Number of bytes to follow cch = @name.bytesize # Length of sheet name # Character length is num of chars not num of bytes cch /= 2 if is_name_utf16be? # Change the UTF-16 name from BE to LE sheetname = is_name_utf16be? ? @name.unpack('v*').pack('n*') : @name grbit = @type | hidden header = [record, length].pack("vv") data = [@offset, grbit, cch, encoding].pack("VvCC") header + data + sheetname end
ruby
{ "resource": "" }
q19079
Writeexcel.Worksheet.parse_filter_expression
train
def parse_filter_expression(expression, tokens) #:nodoc: # The number of tokens will be either 3 (for 1 expression) # or 7 (for 2 expressions). # if (tokens.size == 7) conditional = tokens[3] if conditional =~ /^(and|&&)$/ conditional = 0 elsif conditional =~ /^(or|\|\|)$/ conditional = 1 else raise "Token '#{conditional}' is not a valid conditional " + "in filter expression '#{expression}'" end expression_1 = parse_filter_tokens(expression, tokens[0..2]) expression_2 = parse_filter_tokens(expression, tokens[4..6]) [expression_1, conditional, expression_2].flatten else parse_filter_tokens(expression, tokens) end end
ruby
{ "resource": "" }
q19080
Writeexcel.Worksheet.xf_record_index
train
def xf_record_index(row, col, xf=nil) #:nodoc: if xf.respond_to?(:xf_index) xf.xf_index elsif @row_formats.has_key?(row) @row_formats[row].xf_index elsif @col_formats.has_key?(col) @col_formats[col].xf_index else 0x0F end end
ruby
{ "resource": "" }
q19081
Writeexcel.Worksheet.encode_password
train
def encode_password(password) i = 0 chars = password.split(//) count = chars.size chars.collect! do |char| i += 1 char = char.ord << i low_15 = char & 0x7fff high_15 = char & 0x7fff << 15 high_15 = high_15 >> 15 char = low_15 | high_15 end encoded_password = 0x0000 chars.each { |c| encoded_password ^= c } encoded_password ^= count encoded_password ^= 0xCE4B end
ruby
{ "resource": "" }
q19082
Writeexcel.Worksheet.get_formula_string
train
def get_formula_string(string) #:nodoc: ruby_19 { string = convert_to_ascii_if_ascii(string) } record = 0x0207 # Record identifier length = 0x00 # Bytes to follow # string # Formula string. strlen = string.bytesize # Length of the formula string (chars). encoding = 0 # String encoding. # Handle utf8 strings. if is_utf8?(string) string = utf8_to_16be(string) encoding = 1 end length = 0x03 + string.bytesize # Length of the record data header = [record, length].pack("vv") data = [strlen, encoding].pack("vC") header + data + string end
ruby
{ "resource": "" }
q19083
Writeexcel.Worksheet.store_dimensions
train
def store_dimensions #:nodoc: record = 0x0200 # Record identifier length = 0x000E # Number of bytes to follow reserved = 0x0000 # Reserved by Excel @dimension.increment_row_max @dimension.increment_col_max header = [record, length].pack("vv") fields = [@dimension.row_min, @dimension.row_max, @dimension.col_min, @dimension.col_max, reserved] data = fields.pack("VVvvv") prepend(header, data) end
ruby
{ "resource": "" }
q19084
Writeexcel.Worksheet.store_window2
train
def store_window2 #:nodoc: record = 0x023E # Record identifier length = 0x0012 # Number of bytes to follow grbit = 0x00B6 # Option flags rwTop = @first_row # Top visible row colLeft = @first_col # Leftmost visible column rgbHdr = 0x00000040 # Row/col heading, grid color wScaleSLV = 0x0000 # Zoom in page break preview wScaleNormal = 0x0000 # Zoom in normal view reserved = 0x00000000 # The options flags that comprise $grbit fDspFmla = @display_formulas # 0 - bit fDspGrid = @screen_gridlines # 1 fDspRwCol = @display_headers # 2 fFrozen = frozen? ? 1 : 0 # 3 fDspZeros = display_zeros? ? 1 : 0 # 4 fDefaultHdr = 1 # 5 fArabic = @display_arabic || 0 # 6 fDspGuts = @outline.visible? ? 1 : 0 # 7 fFrozenNoSplit = @frozen_no_split # 0 - bit fSelected = selected? ? 1 : 0 # 1 fPaged = active? ? 1 : 0 # 2 fBreakPreview = 0 # 3 grbit = fDspFmla grbit |= fDspGrid << 1 grbit |= fDspRwCol << 2 grbit |= fFrozen << 3 grbit |= fDspZeros << 4 grbit |= fDefaultHdr << 5 grbit |= fArabic << 6 grbit |= fDspGuts << 7 grbit |= fFrozenNoSplit << 8 grbit |= fSelected << 9 grbit |= fPaged << 10 grbit |= fBreakPreview << 11 header = [record, length].pack("vv") data =[grbit, rwTop, colLeft, rgbHdr, wScaleSLV, wScaleNormal, reserved].pack("vvvVvvV") append(header, data) end
ruby
{ "resource": "" }
q19085
Writeexcel.Worksheet.store_tab_color
train
def store_tab_color #:nodoc: color = @tab_color return if color == 0 record = 0x0862 # Record identifier length = 0x0014 # Number of bytes to follow zero = 0x0000 unknown = 0x0014 store_simple(record, length, record, zero, zero, zero, zero, zero, unknown, zero, color, zero) end
ruby
{ "resource": "" }
q19086
Writeexcel.Worksheet.store_defrow
train
def store_defrow #:nodoc: record = 0x0225 # Record identifier length = 0x0004 # Number of bytes to follow grbit = 0x0000 # Options. height = 0x00FF # Default row height header = [record, length].pack("vv") data = [grbit, height].pack("vv") prepend(header, data) end
ruby
{ "resource": "" }
q19087
Writeexcel.Worksheet.store_defcol
train
def store_defcol #:nodoc: record = 0x0055 # Record identifier length = 0x0002 # Number of bytes to follow colwidth = 0x0008 # Default column width header = [record, length].pack("vv") data = [colwidth].pack("v") prepend(header, data) end
ruby
{ "resource": "" }
q19088
Writeexcel.Worksheet.store_autofilterinfo
train
def store_autofilterinfo #:nodoc: # Only write the record if the worksheet contains an autofilter. return '' if @filter_area.count == 0 record = 0x009D # Record identifier length = 0x0002 # Number of bytes to follow num_filters = @filter_area.count header = [record, length].pack('vv') data = [num_filters].pack('v') prepend(header, data) end
ruby
{ "resource": "" }
q19089
Writeexcel.Worksheet.store_selection
train
def store_selection(first_row=0, first_col=0, last_row = nil, last_col =nil) #:nodoc: record = 0x001D # Record identifier length = 0x000F # Number of bytes to follow pane_position = @active_pane # Pane position row_active = first_row # Active row col_active = first_col # Active column irefAct = 0 # Active cell ref cref = 1 # Number of refs row_first = first_row # First row in reference col_first = first_col # First col in reference row_last = last_row || row_first # Last row in reference col_last = last_col || col_first # Last col in reference # Swap last row/col for first row/col as necessary row_first, row_last = row_last, row_first if row_first > row_last col_first, col_last = col_last, col_first if col_first > col_last header = [record, length].pack('vv') data = [pane_position, row_active, col_active, irefAct, cref, row_first, row_last, col_first, col_last].pack('CvvvvvvCC') append(header, data) end
ruby
{ "resource": "" }
q19090
Writeexcel.Worksheet.store_externcount
train
def store_externcount(count) #:nodoc: record = 0x0016 # Record identifier length = 0x0002 # Number of bytes to follow cxals = count # Number of external references header = [record, length].pack('vv') data = [cxals].pack('v') prepend(header, data) end
ruby
{ "resource": "" }
q19091
Writeexcel.Worksheet.store_setup
train
def store_setup #:nodoc: record = 0x00A1 # Record identifier length = 0x0022 # Number of bytes to follow iPaperSize = @paper_size # Paper size iScale = @print_scale # Print scaling factor iPageStart = @page_start # Starting page number iFitWidth = @fit_width # Fit to number of pages wide iFitHeight = @fit_height # Fit to number of pages high grbit = 0x00 # Option flags iRes = 0x0258 # Print resolution iVRes = 0x0258 # Vertical print resolution numHdr = @margin_header # Header Margin numFtr = @margin_footer # Footer Margin iCopies = 0x01 # Number of copies fLeftToRight = @page_order # Print over then down fLandscape = @orientation # Page orientation fNoPls = 0x0 # Setup not read from printer fNoColor = @black_white # Print black and white fDraft = @draft_quality # Print draft quality fNotes = @print_comments# Print notes fNoOrient = 0x0 # Orientation not set fUsePage = @custom_start # Use custom starting page grbit = fLeftToRight grbit |= fLandscape << 1 grbit |= fNoPls << 2 grbit |= fNoColor << 3 grbit |= fDraft << 4 grbit |= fNotes << 5 grbit |= fNoOrient << 6 grbit |= fUsePage << 7 numHdr = [numHdr].pack('d') numFtr = [numFtr].pack('d') if @byte_order numHdr.reverse! numFtr.reverse! end header = [record, length].pack('vv') data1 = [iPaperSize, iScale, iPageStart, iFitWidth, iFitHeight, grbit, iRes, iVRes].pack("vvvvvvvv") data2 = numHdr + numFtr data3 = [iCopies].pack('v') prepend(header, data1, data2, data3) end
ruby
{ "resource": "" }
q19092
Writeexcel.Worksheet.store_gridset
train
def store_gridset #:nodoc: record = 0x0082 # Record identifier length = 0x0002 # Bytes to follow fGridSet = @print_gridlines == 0 ? 1 : 0 # Boolean flag header = [record, length].pack("vv") data = [fGridSet].pack("v") prepend(header, data) end
ruby
{ "resource": "" }
q19093
Writeexcel.Worksheet.store_wsbool
train
def store_wsbool #:nodoc: record = 0x0081 # Record identifier length = 0x0002 # Bytes to follow grbit = 0x0000 # Option flags # Set the option flags grbit |= 0x0001 # Auto page breaks visible grbit |= 0x0020 if @outline.style != 0 # Auto outline styles grbit |= 0x0040 if @outline.below != 0 # Outline summary below grbit |= 0x0080 if @outline.right != 0 # Outline summary right grbit |= 0x0100 if @fit_page != 0 # Page setup fit to page grbit |= 0x0400 if @outline.visible? # Outline symbols displayed header = [record, length].pack("vv") data = [grbit].pack('v') prepend(header, data) end
ruby
{ "resource": "" }
q19094
Writeexcel.Worksheet.store_password
train
def store_password #:nodoc: # Exit unless sheet protection and password have been specified return unless protect? && @password record = 0x0013 # Record identifier length = 0x0002 # Bytes to follow wPassword = @password # Encoded password header = [record, length].pack("vv") data = [wPassword].pack("v") prepend(header, data) end
ruby
{ "resource": "" }
q19095
Writeexcel.Worksheet.store_table
train
def store_table #:nodoc: return unless compatibility? # Offset from the DBCELL record back to the first ROW of the 32 row block. row_offset = 0 # Track rows that have cell data or modified by set_row(). written_rows = [] # Write the ROW records with updated max/min col fields. # (0 .. @dimension.row_max-1).each do |row| # Skip unless there is cell data in row or the row has been modified. next unless @table[row] or @row_data[row] # Store the rows with data. written_rows.push(row) # Increase the row offset by the length of a ROW record; row_offset += 20 # The max/min cols in the ROW records are the same as in DIMENSIONS. col_min = @dimension.col_min col_max = @dimension.col_max # Write a user specified ROW record (modified by set_row()). if @row_data[row] # Rewrite the min and max cols for user defined row record. packed_row = @row_data[row] packed_row[6..9] = [col_min, col_max].pack('vv') append(packed_row) else # Write a default Row record if there isn't a user defined ROW. write_row_default(row, col_min, col_max) end # If 32 rows have been written or we are at the last row in the # worksheet then write the cell data and the DBCELL record. # if written_rows.size == 32 || row == @dimension.row_max - 1 # Offsets to the first cell of each row. cell_offsets = [] cell_offsets.push(row_offset - 20) # Write the cell data in each row and sum their lengths for the # cell offsets. # written_rows.each do |rw| cell_offset = 0 if @table[rw] @table[rw].each do |clm| next unless clm append(clm) length = clm.bytesize row_offset += length cell_offset += length end end cell_offsets.push(cell_offset) end # The last offset isn't required. cell_offsets.pop # Stores the DBCELL offset for use in the INDEX record. @db_indices.push(@datasize) # Write the DBCELL record. store_dbcell(row_offset, cell_offsets) # Clear the variable for the next block of rows. written_rows = [] cell_offsets = [] row_offset = 0 end end end
ruby
{ "resource": "" }
q19096
Writeexcel.Worksheet.size_col
train
def size_col(col) #:nodoc: # Look up the cell value to see if it has been changed if @col_sizes[col] width = @col_sizes[col] # The relationship is different for user units less than 1. if width < 1 (width *12).to_i else (width *7 +5 ).to_i end else 64 end end
ruby
{ "resource": "" }
q19097
Writeexcel.Worksheet.store_autofilter
train
def store_autofilter(index, operator_1, token_1, #:nodoc: join = nil, operator_2 = nil, token_2 = nil) record = 0x009E length = 0x0000 top10_active = 0 top10_direction = 0 top10_percent = 0 top10_value = 101 grbit = join || 0 optimised_1 = 0 optimised_2 = 0 doper_1 = '' doper_2 = '' string_1 = '' string_2 = '' # Excel used an optimisation in the case of a simple equality. optimised_1 = 1 if operator_1 == 2 optimised_2 = 1 if operator_2 && operator_2 == 2 # Convert non-simple equalities back to type 2. See parse_filter_tokens(). operator_1 = 2 if operator_1 == 22 operator_2 = 2 if operator_2 && operator_2 == 22 # Handle a "Top" style expression. if operator_1 >= 30 # Remove the second expression if present. operator_2 = nil token_2 = nil # Set the active flag. top10_active = 1 if (operator_1 == 30 or operator_1 == 31) top10_direction = 1 end if (operator_1 == 31 or operator_1 == 33) top10_percent = 1 end if (top10_direction == 1) operator_1 = 6 else operator_1 = 3 end top10_value = token_1.to_i token_1 = 0 end grbit |= optimised_1 << 2 grbit |= optimised_2 << 3 grbit |= top10_active << 4 grbit |= top10_direction << 5 grbit |= top10_percent << 6 grbit |= top10_value << 7 doper_1, string_1 = pack_doper(operator_1, token_1) doper_2, string_2 = pack_doper(operator_2, token_2) doper_1 = '' unless doper_1 doper_2 = '' unless doper_2 string_1 = '' unless string_1 string_2 = '' unless string_2 data = [index].pack('v') data += [grbit].pack('v') data += doper_1 + doper_2 + string_1 + string_2 length = data.bytesize header = [record, length].pack('vv') prepend(header, data) end
ruby
{ "resource": "" }
q19098
Writeexcel.Worksheet.pack_doper
train
def pack_doper(operator, token) #:nodoc: doper = '' string = '' # Return default doper for non-defined filters. unless operator return pack_unused_doper, string end if token.to_s =~ /^blanks|nonblanks$/i doper = pack_blanks_doper(operator, token) elsif operator == 2 or !(token.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) # Excel treats all tokens as strings if the operator is equality, =. string = token.to_s ruby_19 { string = convert_to_ascii_if_ascii(string) } encoding = 0 length = string.bytesize # Handle utf8 strings if is_utf8?(string) string = utf8_to_16be(string) encodign = 1 end string = ruby_18 { [encoding].pack('C') + string } || ruby_19 { [encoding].pack('C') + string.force_encoding('BINARY') } doper = pack_string_doper(operator, length) else string = '' doper = pack_number_doper(operator, token) end [doper, string] end
ruby
{ "resource": "" }
q19099
Writeexcel.Worksheet.pack_number_doper
train
def pack_number_doper(operator, number) #:nodoc: number = [number].pack('d') number.reverse! if @byte_order [0x04, operator].pack('CC') + number end
ruby
{ "resource": "" }