_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q11900
ChefZero.RestBase.json_response
train
def json_response(response_code, data, options = {}) options = { pretty: true }.merge(options) do_pretty_json = !!options.delete(:pretty) # make sure we have a proper Boolean. json = FFI_Yajl::Encoder.encode(data, pretty: do_pretty_json) already_json_response(response_code, json, options) end
ruby
{ "resource": "" }
q11901
ChefZero.RestBase.already_json_response
train
def already_json_response(response_code, json_text, options = {}) version_header = FFI_Yajl::Encoder.encode( "min_version" => MIN_API_VERSION.to_s, "max_version" => MAX_API_VERSION.to_s, "request_version" => options[:request_version] || DEFAULT_REQUEST_VERSION.to_s, "response_version" => options[:response_version] || DEFAULT_RESPONSE_VERSION.to_s ) headers = { "Content-Type" => "application/json", "X-Ops-Server-API-Version" => version_header, } headers.merge!(options[:headers]) if options[:headers] [ response_code, headers, json_text ] end
ruby
{ "resource": "" }
q11902
ChefZero.RestBase.build_uri
train
def build_uri(base_uri, rest_path) if server.options[:single_org] # Strip off /organizations/chef if we are in single org mode if rest_path[0..1] != [ "organizations", server.options[:single_org] ] raise "Unexpected URL #{rest_path[0..1]} passed to build_uri in single org mode" end return self.class.build_uri(base_uri, rest_path[2..-1]) end self.class.build_uri(base_uri, rest_path) end
ruby
{ "resource": "" }
q11903
RBHive.TCLIConnection.parse_sasl_params
train
def parse_sasl_params(sasl_params) # Symbilize keys in a hash if sasl_params.kind_of?(Hash) return sasl_params.inject({}) do |memo,(k,v)| memo[k.to_sym] = v; memo end end return nil end
ruby
{ "resource": "" }
q11904
RBHive.TCLIConnection.async_state
train
def async_state(handles) response = @client.GetOperationStatus( Hive2::Thrift::TGetOperationStatusReq.new(operationHandle: prepare_operation_handle(handles)) ) case response.operationState when Hive2::Thrift::TOperationState::FINISHED_STATE return :finished when Hive2::Thrift::TOperationState::INITIALIZED_STATE return :initialized when Hive2::Thrift::TOperationState::RUNNING_STATE return :running when Hive2::Thrift::TOperationState::CANCELED_STATE return :cancelled when Hive2::Thrift::TOperationState::CLOSED_STATE return :closed when Hive2::Thrift::TOperationState::ERROR_STATE return :error when Hive2::Thrift::TOperationState::UKNOWN_STATE return :unknown when Hive2::Thrift::TOperationState::PENDING_STATE return :pending when nil raise "No operation state found for handles - has the session been closed?" else return :state_not_in_protocol end end
ruby
{ "resource": "" }
q11905
RBHive.TCLIConnection.async_fetch
train
def async_fetch(handles, max_rows = 100) # Can't get data from an unfinished query unless async_is_complete?(handles) raise "Can't perform fetch on a query in state: #{async_state(handles)}" end # Fetch and fetch_rows(prepare_operation_handle(handles), :first, max_rows) end
ruby
{ "resource": "" }
q11906
RBHive.TCLIConnection.fetch_rows
train
def fetch_rows(op_handle, orientation = :first, max_rows = 1000) fetch_req = prepare_fetch_results(op_handle, orientation, max_rows) fetch_results = @client.FetchResults(fetch_req) raise_error_if_failed!(fetch_results) rows = fetch_results.results.rows TCLIResultSet.new(rows, TCLISchemaDefinition.new(get_schema_for(op_handle), rows.first)) end
ruby
{ "resource": "" }
q11907
RBHive.TCLIConnection.raise_error_if_failed!
train
def raise_error_if_failed!(result) return if result.status.statusCode == 0 error_message = result.status.errorMessage || 'Execution failed!' raise RBHive::TCLIConnectionError.new(error_message) end
ruby
{ "resource": "" }
q11908
Heroku::Command.Addons.parse_options
train
def parse_options(args) config = {} deprecated_args = [] flag = /^--/ args.size.times do break if args.empty? peek = args.first next unless peek && (peek.match(flag) || peek.match(/=/)) arg = args.shift peek = args.first key = arg if key.match(/=/) deprecated_args << key unless key.match(flag) key, value = key.split('=', 2) elsif peek.nil? || peek.match(flag) value = true else value = args.shift end value = true if value == 'true' config[key.sub(flag, '')] = value if !deprecated_args.empty? out_string = deprecated_args.map{|a| "--#{a}"}.join(' ') display("Warning: non-unix style params have been deprecated, use #{out_string} instead") end end config end
ruby
{ "resource": "" }
q11909
Heroku.Helpers.line_formatter
train
def line_formatter(array) if array.any? {|item| item.is_a?(Array)} cols = [] array.each do |item| if item.is_a?(Array) item.each_with_index { |val,idx| cols[idx] = [cols[idx]||0, (val || '').length].max } end end cols.map { |col| "%-#{col}s" }.join(" ") else "%s" end end
ruby
{ "resource": "" }
q11910
Axlsx.StrData.data=
train
def data=(values=[]) @tag_name = values.first.is_a?(Cell) ? :strCache : :strLit values.each do |value| v = value.is_a?(Cell) ? value.value : value @pt << @type.new(:v => v) end end
ruby
{ "resource": "" }
q11911
Axlsx.PivotTable.relationships
train
def relationships r = Relationships.new r << Relationship.new(cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, "../#{cache_definition.pn}") r end
ruby
{ "resource": "" }
q11912
Axlsx.DataBar.color=
train
def color=(v) @color = v if v.is_a? Color self.color.rgb = v if v.is_a? String @color end
ruby
{ "resource": "" }
q11913
Axlsx.DataBar.to_xml_string
train
def to_xml_string(str="") serialized_tag('dataBar', str) do value_objects.to_xml_string(str) self.color.to_xml_string(str) end end
ruby
{ "resource": "" }
q11914
Axlsx.Package.serialize
train
def serialize(output, confirm_valid=false) return false unless !confirm_valid || self.validate.empty? Relationship.clear_cached_instances Zip::OutputStream.open(output) do |zip| write_parts(zip) end true end
ruby
{ "resource": "" }
q11915
Axlsx.Package.to_stream
train
def to_stream(confirm_valid=false) return false unless !confirm_valid || self.validate.empty? Relationship.clear_cached_instances zip = write_parts(Zip::OutputStream.new(StringIO.new, true)) stream = zip.close_buffer stream.rewind stream end
ruby
{ "resource": "" }
q11916
Axlsx.Package.write_parts
train
def write_parts(zip) p = parts p.each do |part| unless part[:doc].nil? zip.put_next_entry(zip_entry_for_part(part)) part[:doc].to_xml_string(zip) end unless part[:path].nil? zip.put_next_entry(zip_entry_for_part(part)) zip.write IO.read(part[:path]) end end zip end
ruby
{ "resource": "" }
q11917
Axlsx.Package.parts
train
def parts parts = [ {:entry => RELS_PN, :doc => relationships, :schema => RELS_XSD}, {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles, :schema => SML_XSD}, {:entry => CORE_PN, :doc => @core, :schema => CORE_XSD}, {:entry => APP_PN, :doc => @app, :schema => APP_XSD}, {:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships, :schema => RELS_XSD}, {:entry => CONTENT_TYPES_PN, :doc => content_types, :schema => CONTENT_TYPES_XSD}, {:entry => WORKBOOK_PN, :doc => workbook, :schema => SML_XSD} ] workbook.drawings.each do |drawing| parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships, :schema => RELS_XSD} parts << {:entry => "xl/#{drawing.pn}", :doc => drawing, :schema => DRAWING_XSD} end workbook.tables.each do |table| parts << {:entry => "xl/#{table.pn}", :doc => table, :schema => SML_XSD} end workbook.pivot_tables.each do |pivot_table| cache_definition = pivot_table.cache_definition parts << {:entry => "xl/#{pivot_table.rels_pn}", :doc => pivot_table.relationships, :schema => RELS_XSD} parts << {:entry => "xl/#{pivot_table.pn}", :doc => pivot_table} #, :schema => SML_XSD} parts << {:entry => "xl/#{cache_definition.pn}", :doc => cache_definition} #, :schema => SML_XSD} end workbook.comments.each do|comment| if comment.size > 0 parts << { :entry => "xl/#{comment.pn}", :doc => comment, :schema => SML_XSD } parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing, :schema => nil } end end workbook.charts.each do |chart| parts << {:entry => "xl/#{chart.pn}", :doc => chart, :schema => DRAWING_XSD} end workbook.images.each do |image| parts << {:entry => "xl/#{image.pn}", :path => image.image_src} end if use_shared_strings parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings, :schema => SML_XSD} end workbook.worksheets.each do |sheet| parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships, :schema => RELS_XSD} parts << {:entry => "xl/#{sheet.pn}", :doc => sheet, :schema => SML_XSD} end # Sort parts for correct MIME detection parts.sort_by { |part| part[:entry] } end
ruby
{ "resource": "" }
q11918
Axlsx.Package.validate_single_doc
train
def validate_single_doc(schema, doc) schema = Nokogiri::XML::Schema(File.open(schema)) doc = Nokogiri::XML(doc) errors = [] schema.validate(doc).each do |error| errors << error end errors end
ruby
{ "resource": "" }
q11919
Axlsx.Package.content_types
train
def content_types c_types = base_content_types workbook.drawings.each do |drawing| c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}", :ContentType => DRAWING_CT) end workbook.charts.each do |chart| c_types << Axlsx::Override.new(:PartName => "/xl/#{chart.pn}", :ContentType => CHART_CT) end workbook.tables.each do |table| c_types << Axlsx::Override.new(:PartName => "/xl/#{table.pn}", :ContentType => TABLE_CT) end workbook.pivot_tables.each do |pivot_table| c_types << Axlsx::Override.new(:PartName => "/xl/#{pivot_table.pn}", :ContentType => PIVOT_TABLE_CT) c_types << Axlsx::Override.new(:PartName => "/xl/#{pivot_table.cache_definition.pn}", :ContentType => PIVOT_TABLE_CACHE_DEFINITION_CT) end workbook.comments.each do |comment| if comment.size > 0 c_types << Axlsx::Override.new(:PartName => "/xl/#{comment.pn}", :ContentType => COMMENT_CT) end end if workbook.comments.size > 0 c_types << Axlsx::Default.new(:Extension => "vml", :ContentType => VML_DRAWING_CT) end workbook.worksheets.each do |sheet| c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}", :ContentType => WORKSHEET_CT) end exts = workbook.images.map { |image| image.extname.downcase } exts.uniq.each do |ext| ct = if ['jpeg', 'jpg'].include?(ext) JPEG_CT elsif ext == 'gif' GIF_CT elsif ext == 'png' PNG_CT end c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext ) end if use_shared_strings c_types << Axlsx::Override.new(:PartName => "/xl/#{SHARED_STRINGS_PN}", :ContentType => SHARED_STRINGS_CT) end c_types end
ruby
{ "resource": "" }
q11920
Axlsx.Package.base_content_types
train
def base_content_types c_types = ContentType.new() c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX) c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT) c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT) c_types << Override.new(:PartName => "/#{CORE_PN}", :ContentType => CORE_CT) c_types << Override.new(:PartName => "/xl/#{STYLES_PN}", :ContentType => STYLES_CT) c_types << Axlsx::Override.new(:PartName => "/#{WORKBOOK_PN}", :ContentType => WORKBOOK_CT) c_types.lock c_types end
ruby
{ "resource": "" }
q11921
Axlsx.Package.relationships
train
def relationships rels = Axlsx::Relationships.new rels << Relationship.new(self, WORKBOOK_R, WORKBOOK_PN) rels << Relationship.new(self, CORE_R, CORE_PN) rels << Relationship.new(self, APP_R, APP_PN) rels.lock rels end
ruby
{ "resource": "" }
q11922
Axlsx.Pic.hyperlink=
train
def hyperlink=(v, options={}) options[:href] = v if hyperlink.is_a?(Hyperlink) options.each do |o| hyperlink.send("#{o[0]}=", o[1]) if hyperlink.respond_to? "#{o[0]}=" end else @hyperlink = Hyperlink.new(self, options) end hyperlink end
ruby
{ "resource": "" }
q11923
Axlsx.Pic.end_at
train
def end_at(x, y=nil) use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor) @anchor.end_at x, y @anchor.to end
ruby
{ "resource": "" }
q11924
Axlsx.Pic.use_one_cell_anchor
train
def use_one_cell_anchor return if @anchor.is_a?(OneCellAnchor) new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row]) swap_anchor(new_anchor) end
ruby
{ "resource": "" }
q11925
Axlsx.Pic.use_two_cell_anchor
train
def use_two_cell_anchor return if @anchor.is_a?(TwoCellAnchor) new_anchor = TwoCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row]) swap_anchor(new_anchor) end
ruby
{ "resource": "" }
q11926
Axlsx.Pic.swap_anchor
train
def swap_anchor(new_anchor) new_anchor.drawing.anchors.delete(new_anchor) @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor new_anchor.instance_variable_set "@object", @anchor.object @anchor = new_anchor end
ruby
{ "resource": "" }
q11927
Axlsx.ColorScale.add
train
def add(options={}) value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0) colors << Color.new(:rgb => options[:color] || "FF000000") {:cfvo => value_objects.last, :color => colors.last} end
ruby
{ "resource": "" }
q11928
Axlsx.ColorScale.to_xml_string
train
def to_xml_string(str = '') str << '<colorScale>' value_objects.to_xml_string(str) colors.each { |color| color.to_xml_string(str) } str << '</colorScale>' end
ruby
{ "resource": "" }
q11929
Axlsx.ColorScale.initialize_default_cfvos
train
def initialize_default_cfvos(user_cfvos) defaults = self.class.default_cfvos user_cfvos.each_with_index do |cfvo, index| if index < defaults.size cfvo = defaults[index].merge(cfvo) end add cfvo end while colors.size < defaults.size add defaults[colors.size - 1] end end
ruby
{ "resource": "" }
q11930
Axlsx.Axes.add_axis
train
def add_axis(name, axis_class) axis = axis_class.new set_cross_axis(axis) axes << [name, axis] end
ruby
{ "resource": "" }
q11931
Axlsx.SharedStringsTable.to_xml_string
train
def to_xml_string(str='') Axlsx::sanitize(@shared_xml_string) str << ('<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '"') str << (' count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '"') str << (' xml:space="' << xml_space.to_s << '">' << @shared_xml_string << '</sst>') end
ruby
{ "resource": "" }
q11932
Axlsx.SharedStringsTable.resolve
train
def resolve(cells) cells.each do |cell| cell_hash = cell.value if index = @unique_cells[cell_hash] cell.send :ssti=, index else cell.send :ssti=, @index @shared_xml_string << '<si>' << CellSerializer.run_xml_string(cell) << '</si>' @unique_cells[cell_hash] = @index @index += 1 end end end
ruby
{ "resource": "" }
q11933
Axlsx.WorksheetHyperlinks.to_xml_string
train
def to_xml_string(str='') return if empty? str << '<hyperlinks>' each { |hyperlink| hyperlink.to_xml_string(str) } str << '</hyperlinks>' end
ruby
{ "resource": "" }
q11934
Axlsx.Workbook.sheet_by_name
train
def sheet_by_name(name) index = @worksheets.index { |sheet| sheet.name == name } @worksheets[index] if index end
ruby
{ "resource": "" }
q11935
Axlsx.Workbook.insert_worksheet
train
def insert_worksheet(index=0, options={}) worksheet = Worksheet.new(self, options) @worksheets.delete_at(@worksheets.size - 1) @worksheets.insert(index, worksheet) yield worksheet if block_given? worksheet end
ruby
{ "resource": "" }
q11936
Axlsx.Workbook.relationships
train
def relationships r = Relationships.new @worksheets.each do |sheet| r << Relationship.new(sheet, WORKSHEET_R, WORKSHEET_PN % (r.size+1)) end pivot_tables.each_with_index do |pivot_table, index| r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, PIVOT_TABLE_CACHE_DEFINITION_PN % (index+1)) end r << Relationship.new(self, STYLES_R, STYLES_PN) if use_shared_strings r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN) end r end
ruby
{ "resource": "" }
q11937
Axlsx.Workbook.[]
train
def [](cell_def) sheet_name = cell_def.split('!')[0] if cell_def.match('!') worksheet = self.worksheets.select { |s| s.name == sheet_name }.first raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet) worksheet[cell_def.gsub(/.+!/,"")] end
ruby
{ "resource": "" }
q11938
Axlsx.Workbook.to_xml_string
train
def to_xml_string(str='') add_worksheet(name: 'Sheet1') unless worksheets.size > 0 str << '<?xml version="1.0" encoding="UTF-8"?>' str << ('<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">') str << ('<workbookPr date1904="' << @@date1904.to_s << '"/>') views.to_xml_string(str) str << '<sheets>' if is_reversed worksheets.reverse_each { |sheet| sheet.to_sheet_node_xml_string(str) } else worksheets.each { |sheet| sheet.to_sheet_node_xml_string(str) } end str << '</sheets>' defined_names.to_xml_string(str) unless pivot_tables.empty? str << '<pivotCaches>' pivot_tables.each do |pivot_table| str << ('<pivotCache cacheId="' << pivot_table.cache_definition.cache_id.to_s << '" r:id="' << pivot_table.cache_definition.rId << '"/>') end str << '</pivotCaches>' end str << '</workbook>' end
ruby
{ "resource": "" }
q11939
Axlsx.PageMargins.set
train
def set(margins) margins.select do |k, v| next unless [:left, :right, :top, :bottom, :header, :footer].include? k send("#{k}=", v) end end
ruby
{ "resource": "" }
q11940
Axlsx.Marker.coord
train
def coord(col, row=0) coordinates = parse_coord_args(col, row) self.col = coordinates[0] self.row = coordinates[1] end
ruby
{ "resource": "" }
q11941
Axlsx.Marker.parse_coord_args
train
def parse_coord_args(x, y=0) if x.is_a?(String) x, y = *Axlsx::name_to_indices(x) end if x.is_a?(Cell) x, y = *x.pos end if x.is_a?(Array) x, y = *x end [x, y] end
ruby
{ "resource": "" }
q11942
Axlsx.Comments.add_comment
train
def add_comment(options={}) raise ArgumentError, "Comment require an author" unless options[:author] raise ArgumentError, "Comment requires text" unless options[:text] raise ArgumentError, "Comment requires ref" unless options[:ref] self << Comment.new(self, options) yield last if block_given? last end
ruby
{ "resource": "" }
q11943
Axlsx.RichTextRun.autowidth
train
def autowidth(widtharray) return if value.nil? if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text first = true value.to_s.split(/\r?\n/, -1).each do |line| if first first = false else widtharray << 0 end widtharray[-1] += string_width(line, font_size) end else widtharray[-1] += string_width(value.to_s, font_size) end widtharray end
ruby
{ "resource": "" }
q11944
Axlsx.RichTextRun.to_xml_string
train
def to_xml_string(str = '') valid = RichTextRun::INLINE_STYLES data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }] data = data.select { |key, value| valid.include?(key) && !value.nil? } str << '<r><rPr>' data.keys.each do |key| case key when :font_name str << ('<rFont val="' << font_name << '"/>') when :color str << data[key].to_xml_string else str << ('<' << key.to_s << ' val="' << xml_value(data[key]) << '"/>') end end clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s)) str << ('</rPr><t>' << clean_value << '</t></r>') end
ruby
{ "resource": "" }
q11945
Axlsx.RichTextRun.string_width
train
def string_width(string, font_size) font_scale = font_size / 10.0 string.count(Worksheet::THIN_CHARS) * font_scale end
ruby
{ "resource": "" }
q11946
Axlsx.RichTextRun.font_size
train
def font_size return sz if sz font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0] (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz end
ruby
{ "resource": "" }
q11947
Axlsx.GradientFill.validate_format_percentage
train
def validate_format_percentage(name, value) DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0} end
ruby
{ "resource": "" }
q11948
Axlsx.AbstractContentType.to_xml_string
train
def to_xml_string(node_name = '', str = '') str << "<#{node_name} " str << instance_values.map { |key, value| Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ') str << '/>' end
ruby
{ "resource": "" }
q11949
Axlsx.DataValidations.to_xml_string
train
def to_xml_string(str = "") return if empty? str << "<dataValidations count='#{size}'>" each { |item| item.to_xml_string(str) } str << '</dataValidations>' end
ruby
{ "resource": "" }
q11950
Axlsx.IconSet.initialize_value_objects
train
def initialize_value_objects @value_objects = SimpleTypedList.new Cfvo @value_objects.concat [Cfvo.new(:type => :percent, :val => 0), Cfvo.new(:type => :percent, :val => 33), Cfvo.new(:type => :percent, :val => 67)] @value_objects.lock end
ruby
{ "resource": "" }
q11951
Axlsx.Storage.to_s
train
def to_s data = [@name.concat(Array.new(32-@name.size, 0)), @name_size, @type, @color, @left, @right, @child, @created, @modified, @sector, @size].flatten data.pack(PACKING) end
ruby
{ "resource": "" }
q11952
Axlsx.FilterColumn.col_id=
train
def col_id=(column_index) column_index = column_index.col if column_index.is_a?(Cell) Axlsx.validate_unsigned_int column_index @col_id = column_index end
ruby
{ "resource": "" }
q11953
Axlsx.FilterColumn.apply
train
def apply(row, offset) row.hidden = @filter.apply(row.cells[offset+col_id.to_i]) end
ruby
{ "resource": "" }
q11954
Axlsx.SheetData.to_xml_string
train
def to_xml_string(str = '') str << '<sheetData>' worksheet.rows.each_with_index do |row, index| row.to_xml_string(index, str) end str << '</sheetData>' end
ruby
{ "resource": "" }
q11955
Axlsx.DefinedNames.to_xml_string
train
def to_xml_string(str = '') return if empty? str << '<definedNames>' each { |defined_name| defined_name.to_xml_string(str) } str << '</definedNames>' end
ruby
{ "resource": "" }
q11956
Axlsx.ConditionalFormatting.add_rule
train
def add_rule(rule) if rule.is_a? Axlsx::ConditionalFormattingRule @rules << rule elsif rule.is_a? Hash @rules << ConditionalFormattingRule.new(rule) end end
ruby
{ "resource": "" }
q11957
Axlsx.ConditionalFormatting.to_xml_string
train
def to_xml_string(str = '') str << ('<conditionalFormatting sqref="' << sqref << '">') str << rules.collect{ |rule| rule.to_xml_string }.join(' ') str << '</conditionalFormatting>' end
ruby
{ "resource": "" }
q11958
Axlsx.Axis.label_rotation=
train
def label_rotation=(v) Axlsx::validate_int(v) adjusted = v.to_i * 60000 Axlsx::validate_angle(adjusted) @label_rotation = adjusted end
ruby
{ "resource": "" }
q11959
Axlsx.Axis.title=
train
def title=(v) DataTypeValidator.validate "#{self.class}.title", [String, Cell], v @title ||= Title.new if v.is_a?(String) @title.text = v elsif v.is_a?(Cell) @title.cell = v end end
ruby
{ "resource": "" }
q11960
Axlsx.Worksheet.initialize_page_options
train
def initialize_page_options(options) @page_margins = PageMargins.new options[:page_margins] if options[:page_margins] @page_setup = PageSetup.new options[:page_setup] if options[:page_setup] @print_options = PrintOptions.new options[:print_options] if options[:print_options] @header_footer = HeaderFooter.new options[:header_footer] if options[:header_footer] @row_breaks = RowBreaks.new @col_breaks = ColBreaks.new end
ruby
{ "resource": "" }
q11961
Axlsx.Worksheet.add_conditional_formatting
train
def add_conditional_formatting(cells, rules) cf = ConditionalFormatting.new( :sqref => cells ) cf.add_rules rules conditional_formattings << cf conditional_formattings end
ruby
{ "resource": "" }
q11962
Axlsx.Worksheet.add_data_validation
train
def add_data_validation(cells, data_validation) dv = DataValidation.new(data_validation) dv.sqref = cells data_validations << dv end
ruby
{ "resource": "" }
q11963
Axlsx.Worksheet.add_chart
train
def add_chart(chart_type, options={}) chart = worksheet_drawing.add_chart(chart_type, options) yield chart if block_given? chart end
ruby
{ "resource": "" }
q11964
Axlsx.Worksheet.column_widths
train
def column_widths(*widths) widths.each_with_index do |value, index| next if value == nil Axlsx::validate_unsigned_numeric(value) unless value == nil find_or_create_column_info(index).width = value end end
ruby
{ "resource": "" }
q11965
Axlsx.Worksheet.col_style
train
def col_style(index, style, options={}) offset = options.delete(:row_offset) || 0 cells = @rows[(offset..-1)].map { |row| row[index] }.flatten.compact cells.each { |cell| cell.style = style } end
ruby
{ "resource": "" }
q11966
Axlsx.Worksheet.row_style
train
def row_style(index, style, options={}) offset = options.delete(:col_offset) || 0 cells = cols[(offset..-1)].map { |column| column[index] }.flatten.compact cells.each { |cell| cell.style = style } end
ruby
{ "resource": "" }
q11967
Axlsx.Worksheet.to_sheet_node_xml_string
train
def to_sheet_node_xml_string(str='') add_autofilter_defined_name_to_workbook str << '<sheet ' serialized_attributes str str << ('name="' << name << '" ') str << ('r:id="' << rId << '"></sheet>') end
ruby
{ "resource": "" }
q11968
Axlsx.Worksheet.to_xml_string
train
def to_xml_string str='' add_autofilter_defined_name_to_workbook auto_filter.apply if auto_filter.range str << '<?xml version="1.0" encoding="UTF-8"?>' str << worksheet_node serializable_parts.each do |item| item.to_xml_string(str) if item end str << '</worksheet>' end
ruby
{ "resource": "" }
q11969
Axlsx.Worksheet.relationships
train
def relationships r = Relationships.new r + [tables.relationships, worksheet_comments.relationships, hyperlinks.relationships, worksheet_drawing.relationship, pivot_tables.relationships].flatten.compact || [] r end
ruby
{ "resource": "" }
q11970
Axlsx.Worksheet.name_to_cell
train
def name_to_cell(name) col_index, row_index = *Axlsx::name_to_indices(name) r = rows[row_index] r[col_index] if r end
ruby
{ "resource": "" }
q11971
Axlsx.Worksheet.outline_level_rows
train
def outline_level_rows(start_index, end_index, level = 1, collapsed = true) outline rows, (start_index..end_index), level, collapsed end
ruby
{ "resource": "" }
q11972
Axlsx.Worksheet.outline_level_columns
train
def outline_level_columns(start_index, end_index, level = 1, collapsed = true) outline column_info, (start_index..end_index), level, collapsed end
ruby
{ "resource": "" }
q11973
Axlsx.Row.to_xml_string
train
def to_xml_string(r_index, str = '') serialized_tag('row', str, :r => r_index + 1) do tmp = '' # time / memory tradeoff, lots of calls to rubyzip costs more # time.. each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, tmp) } str << tmp end end
ruby
{ "resource": "" }
q11974
Axlsx.Row.add_cell
train
def add_cell(value = '', options = {}) c = Cell.new(self, value, options) self << c worksheet.send(:update_column_info, self, []) c end
ruby
{ "resource": "" }
q11975
Axlsx.Row.color=
train
def color=(color) each_with_index do | cell, index | cell.color = color.is_a?(Array) ? color[index] : color end end
ruby
{ "resource": "" }
q11976
Axlsx.Row.style=
train
def style=(style) each_with_index do | cell, index | cell.style = style.is_a?(Array) ? style[index] : style end end
ruby
{ "resource": "" }
q11977
Axlsx.Row.array_to_cells
train
def array_to_cells(values, options={}) DataTypeValidator.validate :array_to_cells, Array, values types, style, formula_values = options.delete(:types), options.delete(:style), options.delete(:formula_values) values.each_with_index do |value, index| options[:style] = style.is_a?(Array) ? style[index] : style if style options[:type] = types.is_a?(Array) ? types[index] : types if types options[:formula_value] = formula_values[index] if formula_values.is_a?(Array) self[index] = Cell.new(self, value, options) end end
ruby
{ "resource": "" }
q11978
Axlsx.Drawing.add_image
train
def add_image(options={}) if options[:end_at] TwoCellAnchor.new(self, options).add_pic(options) else OneCellAnchor.new(self, options) end @anchors.last.object end
ruby
{ "resource": "" }
q11979
Axlsx.Drawing.add_chart
train
def add_chart(chart_type, options={}) TwoCellAnchor.new(self, options) @anchors.last.add_chart(chart_type, options) end
ruby
{ "resource": "" }
q11980
Axlsx.Drawing.charts
train
def charts charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) } charts.map { |a| a.object.chart } end
ruby
{ "resource": "" }
q11981
Axlsx.Drawing.hyperlinks
train
def hyperlinks links = self.images.select { |a| a.hyperlink.is_a?(Hyperlink) } links.map { |a| a.hyperlink } end
ruby
{ "resource": "" }
q11982
Axlsx.Drawing.images
train
def images images = @anchors.select { |a| a.object.is_a?(Pic) } images.map { |a| a.object } end
ruby
{ "resource": "" }
q11983
Axlsx.Drawing.relationships
train
def relationships r = Relationships.new child_objects.each { |child| r << child.relationship } r end
ruby
{ "resource": "" }
q11984
Axlsx.SheetPr.to_xml_string
train
def to_xml_string(str = '') update_properties str << "<sheetPr #{serialized_attributes}>" tab_color.to_xml_string(str, 'tabColor') if tab_color outline_pr.to_xml_string(str) if @outline_pr page_setup_pr.to_xml_string(str) str << "</sheetPr>" end
ruby
{ "resource": "" }
q11985
Axlsx.Pie3DChart.to_xml_string
train
def to_xml_string(str = '') super(str) do str << '<c:pie3DChart>' str << ('<c:varyColors val="' << vary_colors.to_s << '"/>') @series.each { |ser| ser.to_xml_string(str) } d_lbls.to_xml_string(str) if @d_lbls str << '</c:pie3DChart>' end end
ruby
{ "resource": "" }
q11986
Axlsx.WorkbookViews.to_xml_string
train
def to_xml_string(str = '') return if empty? str << "<bookViews>" each { |view| view.to_xml_string(str) } str << '</bookViews>' end
ruby
{ "resource": "" }
q11987
Axlsx.Col.update_width
train
def update_width(cell, fixed_width=nil, use_autowidth=true) if fixed_width.is_a? Numeric self.width = fixed_width elsif use_autowidth cell_width = cell.autowidth self.width = cell_width unless (width || 0) > (cell_width || 0) end end
ruby
{ "resource": "" }
q11988
Axlsx.Parser.parse_symbol
train
def parse_symbol attr_name, xpath v = parse_value xpath v = v.to_sym unless v.nil? send("#{attr_name}=", v) end
ruby
{ "resource": "" }
q11989
Axlsx.Parser.parse_integer
train
def parse_integer attr_name, xpath v = parse_value xpath v = v.to_i if v.respond_to?(:to_i) send("#{attr_name}=", v) end
ruby
{ "resource": "" }
q11990
Axlsx.Parser.parse_float
train
def parse_float attr_name, xpath v = parse_value xpath v = v.to_f if v.respond_to?(:to_f) send("#{attr_name}=", v) end
ruby
{ "resource": "" }
q11991
Axlsx.Parser.parse_value
train
def parse_value xpath node = parser_xml.xpath(xpath) return nil if node.empty? node.text.strip end
ruby
{ "resource": "" }
q11992
Axlsx.WorksheetDrawing.add_chart
train
def add_chart(chart_type, options) @drawing ||= Drawing.new worksheet drawing.add_chart(chart_type, options) end
ruby
{ "resource": "" }
q11993
Axlsx.ProtectedRanges.add_range
train
def add_range(cells) sqref = if cells.is_a?(String) cells elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array) Axlsx::cell_range(cells, false) end self << ProtectedRange.new(:sqref => sqref, :name => "Range#{size}") last end
ruby
{ "resource": "" }
q11994
Axlsx.ProtectedRanges.to_xml_string
train
def to_xml_string(str = '') return if empty? str << '<protectedRanges>' each { |range| range.to_xml_string(str) } str << '</protectedRanges>' end
ruby
{ "resource": "" }
q11995
Axlsx.AutoFilter.add_column
train
def add_column(col_id, filter_type, options = {}) columns << FilterColumn.new(col_id, filter_type, options) columns.last end
ruby
{ "resource": "" }
q11996
Axlsx.AutoFilter.apply
train
def apply first_cell, last_cell = range.split(':') start_point = Axlsx::name_to_indices(first_cell) end_point = Axlsx::name_to_indices(last_cell) # The +1 is so we skip the header row with the filter drop downs rows = worksheet.rows[(start_point.last+1)..end_point.last] || [] column_offset = start_point.first columns.each do |column| rows.each do |row| next if row.hidden column.apply(row, column_offset) end end end
ruby
{ "resource": "" }
q11997
Axlsx.SimpleTypedList.delete
train
def delete(v) return unless include? v raise ArgumentError, "Item is protected and cannot be deleted" if protected? index(v) @list.delete v end
ruby
{ "resource": "" }
q11998
Axlsx.SimpleTypedList.[]=
train
def []=(index, v) DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v raise ArgumentError, "Item is protected and cannot be changed" if protected? index @list[index] = v v end
ruby
{ "resource": "" }
q11999
Axlsx.SerializedAttributes.serialized_tag
train
def serialized_tag(tagname, str, additional_attributes = {}, &block) str << "<#{tagname} " serialized_attributes(str, additional_attributes) if block_given? str << '>' yield str << "</#{tagname}>" else str << '/>' end end
ruby
{ "resource": "" }