repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_post_processing.rb
HQMF2.DataCriteriaPostProcessing.handle_mapping_template
def handle_mapping_template(mapping) if mapping if mapping[:valueset_path] && @entry.at_xpath(mapping[:valueset_path]) @code_list_xpath = mapping[:valueset_path] end @value = DataCriteriaMethods.parse_value(@entry, mapping[:result_path]) if mapping[:result_path] end end
ruby
def handle_mapping_template(mapping) if mapping if mapping[:valueset_path] && @entry.at_xpath(mapping[:valueset_path]) @code_list_xpath = mapping[:valueset_path] end @value = DataCriteriaMethods.parse_value(@entry, mapping[:result_path]) if mapping[:result_path] end end
[ "def", "handle_mapping_template", "(", "mapping", ")", "if", "mapping", "if", "mapping", "[", ":valueset_path", "]", "&&", "@entry", ".", "at_xpath", "(", "mapping", "[", ":valueset_path", "]", ")", "@code_list_xpath", "=", "mapping", "[", ":valueset_path", "]", "end", "@value", "=", "DataCriteriaMethods", ".", "parse_value", "(", "@entry", ",", "mapping", "[", ":result_path", "]", ")", "if", "mapping", "[", ":result_path", "]", "end", "end" ]
Set the value and code_list_xpath using the template mapping held in the ValueSetHelper class
[ "Set", "the", "value", "and", "code_list_xpath", "using", "the", "template", "mapping", "held", "in", "the", "ValueSetHelper", "class" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_post_processing.rb#L41-L48
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_post_processing.rb
HQMF2.DataCriteriaPostProcessing.handle_derived_specific_occurrences
def handle_derived_specific_occurrences return unless @definition == 'derived' # remove "_source" from source data critera. It gets added in in SpecificOccurrenceAndSource but # when it gets added we have not yet determined the definition of the data criteria so we cannot # skip adding it. Determining the definition before SpecificOccurrenceAndSource processes doesn't # work because we need to know if it is a specific occurrence to be able to figure out the definition @source_data_criteria = @source_data_criteria.gsub("_source",'') if @source_data_criteria # Adds a child if none exists (specifically the source criteria) @children_criteria << @source_data_criteria if @children_criteria.empty? return if @children_criteria.length != 1 || (@source_data_criteria.present? && @children_criteria.first != @source_data_criteria) # if child.first is nil, it will be caught in the second statement reference_criteria = @data_criteria_references[@children_criteria.first] return if reference_criteria.nil? @is_derived_specific_occurrence_variable = true # easier to track than all testing all features of these cases @subset_operators ||= reference_criteria.subset_operators @derivation_operator ||= reference_criteria.derivation_operator @description = reference_criteria.description @variable = reference_criteria.variable end
ruby
def handle_derived_specific_occurrences return unless @definition == 'derived' # remove "_source" from source data critera. It gets added in in SpecificOccurrenceAndSource but # when it gets added we have not yet determined the definition of the data criteria so we cannot # skip adding it. Determining the definition before SpecificOccurrenceAndSource processes doesn't # work because we need to know if it is a specific occurrence to be able to figure out the definition @source_data_criteria = @source_data_criteria.gsub("_source",'') if @source_data_criteria # Adds a child if none exists (specifically the source criteria) @children_criteria << @source_data_criteria if @children_criteria.empty? return if @children_criteria.length != 1 || (@source_data_criteria.present? && @children_criteria.first != @source_data_criteria) # if child.first is nil, it will be caught in the second statement reference_criteria = @data_criteria_references[@children_criteria.first] return if reference_criteria.nil? @is_derived_specific_occurrence_variable = true # easier to track than all testing all features of these cases @subset_operators ||= reference_criteria.subset_operators @derivation_operator ||= reference_criteria.derivation_operator @description = reference_criteria.description @variable = reference_criteria.variable end
[ "def", "handle_derived_specific_occurrences", "return", "unless", "@definition", "==", "'derived'", "# remove \"_source\" from source data critera. It gets added in in SpecificOccurrenceAndSource but", "# when it gets added we have not yet determined the definition of the data criteria so we cannot", "# skip adding it. Determining the definition before SpecificOccurrenceAndSource processes doesn't", "# work because we need to know if it is a specific occurrence to be able to figure out the definition", "@source_data_criteria", "=", "@source_data_criteria", ".", "gsub", "(", "\"_source\"", ",", "''", ")", "if", "@source_data_criteria", "# Adds a child if none exists (specifically the source criteria)", "@children_criteria", "<<", "@source_data_criteria", "if", "@children_criteria", ".", "empty?", "return", "if", "@children_criteria", ".", "length", "!=", "1", "||", "(", "@source_data_criteria", ".", "present?", "&&", "@children_criteria", ".", "first", "!=", "@source_data_criteria", ")", "# if child.first is nil, it will be caught in the second statement", "reference_criteria", "=", "@data_criteria_references", "[", "@children_criteria", ".", "first", "]", "return", "if", "reference_criteria", ".", "nil?", "@is_derived_specific_occurrence_variable", "=", "true", "# easier to track than all testing all features of these cases", "@subset_operators", "||=", "reference_criteria", ".", "subset_operators", "@derivation_operator", "||=", "reference_criteria", ".", "derivation_operator", "@description", "=", "reference_criteria", ".", "description", "@variable", "=", "reference_criteria", ".", "variable", "end" ]
Apply some elements from the reference_criteria to the derived specific occurrence
[ "Apply", "some", "elements", "from", "the", "reference_criteria", "to", "the", "derived", "specific", "occurrence" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_post_processing.rb#L62-L83
train
projectcypress/health-data-standards
lib/hqmf-parser/converter/pass1/data_criteria_converter.rb
HQMF.DataCriteriaConverter.create_group_data_criteria
def create_group_data_criteria(preconditions, type, value, parent_id, id, standard_category, qds_data_type) extract_group_data_criteria_tree(HQMF::DataCriteria::UNION,preconditions, type, parent_id) end
ruby
def create_group_data_criteria(preconditions, type, value, parent_id, id, standard_category, qds_data_type) extract_group_data_criteria_tree(HQMF::DataCriteria::UNION,preconditions, type, parent_id) end
[ "def", "create_group_data_criteria", "(", "preconditions", ",", "type", ",", "value", ",", "parent_id", ",", "id", ",", "standard_category", ",", "qds_data_type", ")", "extract_group_data_criteria_tree", "(", "HQMF", "::", "DataCriteria", "::", "UNION", ",", "preconditions", ",", "type", ",", "parent_id", ")", "end" ]
grouping data criteria are used to allow a single reference off of a temporal reference or subset operator grouping data criteria can reference either regular data criteria as children, or other grouping data criteria
[ "grouping", "data", "criteria", "are", "used", "to", "allow", "a", "single", "reference", "off", "of", "a", "temporal", "reference", "or", "subset", "operator", "grouping", "data", "criteria", "can", "reference", "either", "regular", "data", "criteria", "as", "children", "or", "other", "grouping", "data", "criteria" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb#L46-L48
train
projectcypress/health-data-standards
lib/hqmf-parser/converter/pass1/data_criteria_converter.rb
HQMF.DataCriteriaConverter.extract_group_data_criteria_tree
def extract_group_data_criteria_tree(conjunction, preconditions, type, parent_id) children = [] preconditions.each do |precondition| if (precondition.comparison?) if (precondition.reference.id == HQMF::Document::MEASURE_PERIOD_ID) children << measure_period_criteria else children << v2_data_criteria_by_id[precondition.reference.id] end else converted_conjunction = convert_grouping_conjunction(precondition.conjunction_code) children << extract_group_data_criteria_tree(converted_conjunction, precondition.preconditions, type, parent_id) end end # if we have just one child element, just return it. An AND or OR of a single item is not useful. if (children.size > 1) build_group_data_criteria(children, type, parent_id, conjunction) else children.first end end
ruby
def extract_group_data_criteria_tree(conjunction, preconditions, type, parent_id) children = [] preconditions.each do |precondition| if (precondition.comparison?) if (precondition.reference.id == HQMF::Document::MEASURE_PERIOD_ID) children << measure_period_criteria else children << v2_data_criteria_by_id[precondition.reference.id] end else converted_conjunction = convert_grouping_conjunction(precondition.conjunction_code) children << extract_group_data_criteria_tree(converted_conjunction, precondition.preconditions, type, parent_id) end end # if we have just one child element, just return it. An AND or OR of a single item is not useful. if (children.size > 1) build_group_data_criteria(children, type, parent_id, conjunction) else children.first end end
[ "def", "extract_group_data_criteria_tree", "(", "conjunction", ",", "preconditions", ",", "type", ",", "parent_id", ")", "children", "=", "[", "]", "preconditions", ".", "each", "do", "|", "precondition", "|", "if", "(", "precondition", ".", "comparison?", ")", "if", "(", "precondition", ".", "reference", ".", "id", "==", "HQMF", "::", "Document", "::", "MEASURE_PERIOD_ID", ")", "children", "<<", "measure_period_criteria", "else", "children", "<<", "v2_data_criteria_by_id", "[", "precondition", ".", "reference", ".", "id", "]", "end", "else", "converted_conjunction", "=", "convert_grouping_conjunction", "(", "precondition", ".", "conjunction_code", ")", "children", "<<", "extract_group_data_criteria_tree", "(", "converted_conjunction", ",", "precondition", ".", "preconditions", ",", "type", ",", "parent_id", ")", "end", "end", "# if we have just one child element, just return it. An AND or OR of a single item is not useful.", "if", "(", "children", ".", "size", ">", "1", ")", "build_group_data_criteria", "(", "children", ",", "type", ",", "parent_id", ",", "conjunction", ")", "else", "children", ".", "first", "end", "end" ]
pull the children data criteria out of a set of preconditions
[ "pull", "the", "children", "data", "criteria", "out", "of", "a", "set", "of", "preconditions" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb#L73-L96
train
projectcypress/health-data-standards
lib/hqmf-parser/converter/pass1/data_criteria_converter.rb
HQMF.DataCriteriaConverter.create_measure_period_v1_data_criteria
def create_measure_period_v1_data_criteria(doc,measure_period,v1_data_criteria_by_id) attributes = doc[:attributes] attributes.keys.each {|key| attributes[key.to_s] = attributes[key]} measure_period_key = attributes['MEASUREMENT_PERIOD'][:id] measure_start_key = attributes['MEASUREMENT_START_DATE'][:id] measure_end_key = attributes['MEASUREMENT_END_DATE'][:id] @measure_period_v1_keys = {measure_start: measure_start_key, measure_end: measure_end_key, measure_period: measure_period_key} type = 'variable' code_list_id,negation_code_list_id,property,status,field_values,effective_time,inline_code_list,children_criteria,derivation_operator,temporal_references,subset_operators=nil ##### ## ######### SET MEASURE PERIOD ## ##### measure_period_id = HQMF::Document::MEASURE_PERIOD_ID value = measure_period measure_criteria = HQMF::DataCriteria.new(measure_period_id,measure_period_id,nil,measure_period_id,code_list_id,children_criteria,derivation_operator,measure_period_id,status, value,field_values,effective_time,inline_code_list, false, nil, temporal_references,subset_operators,nil,nil) # set the measure period data criteria for all measure period keys v1_data_criteria_by_id[measure_period_key] = measure_criteria v1_data_criteria_by_id[measure_start_key] = measure_criteria v1_data_criteria_by_id[measure_end_key] = measure_criteria @measure_period_criteria = measure_criteria end
ruby
def create_measure_period_v1_data_criteria(doc,measure_period,v1_data_criteria_by_id) attributes = doc[:attributes] attributes.keys.each {|key| attributes[key.to_s] = attributes[key]} measure_period_key = attributes['MEASUREMENT_PERIOD'][:id] measure_start_key = attributes['MEASUREMENT_START_DATE'][:id] measure_end_key = attributes['MEASUREMENT_END_DATE'][:id] @measure_period_v1_keys = {measure_start: measure_start_key, measure_end: measure_end_key, measure_period: measure_period_key} type = 'variable' code_list_id,negation_code_list_id,property,status,field_values,effective_time,inline_code_list,children_criteria,derivation_operator,temporal_references,subset_operators=nil ##### ## ######### SET MEASURE PERIOD ## ##### measure_period_id = HQMF::Document::MEASURE_PERIOD_ID value = measure_period measure_criteria = HQMF::DataCriteria.new(measure_period_id,measure_period_id,nil,measure_period_id,code_list_id,children_criteria,derivation_operator,measure_period_id,status, value,field_values,effective_time,inline_code_list, false, nil, temporal_references,subset_operators,nil,nil) # set the measure period data criteria for all measure period keys v1_data_criteria_by_id[measure_period_key] = measure_criteria v1_data_criteria_by_id[measure_start_key] = measure_criteria v1_data_criteria_by_id[measure_end_key] = measure_criteria @measure_period_criteria = measure_criteria end
[ "def", "create_measure_period_v1_data_criteria", "(", "doc", ",", "measure_period", ",", "v1_data_criteria_by_id", ")", "attributes", "=", "doc", "[", ":attributes", "]", "attributes", ".", "keys", ".", "each", "{", "|", "key", "|", "attributes", "[", "key", ".", "to_s", "]", "=", "attributes", "[", "key", "]", "}", "measure_period_key", "=", "attributes", "[", "'MEASUREMENT_PERIOD'", "]", "[", ":id", "]", "measure_start_key", "=", "attributes", "[", "'MEASUREMENT_START_DATE'", "]", "[", ":id", "]", "measure_end_key", "=", "attributes", "[", "'MEASUREMENT_END_DATE'", "]", "[", ":id", "]", "@measure_period_v1_keys", "=", "{", "measure_start", ":", "measure_start_key", ",", "measure_end", ":", "measure_end_key", ",", "measure_period", ":", "measure_period_key", "}", "type", "=", "'variable'", "code_list_id", ",", "negation_code_list_id", ",", "property", ",", "status", ",", "field_values", ",", "effective_time", ",", "inline_code_list", ",", "children_criteria", ",", "derivation_operator", ",", "temporal_references", ",", "subset_operators", "=", "nil", "#####", "##", "######### SET MEASURE PERIOD", "##", "#####", "measure_period_id", "=", "HQMF", "::", "Document", "::", "MEASURE_PERIOD_ID", "value", "=", "measure_period", "measure_criteria", "=", "HQMF", "::", "DataCriteria", ".", "new", "(", "measure_period_id", ",", "measure_period_id", ",", "nil", ",", "measure_period_id", ",", "code_list_id", ",", "children_criteria", ",", "derivation_operator", ",", "measure_period_id", ",", "status", ",", "value", ",", "field_values", ",", "effective_time", ",", "inline_code_list", ",", "false", ",", "nil", ",", "temporal_references", ",", "subset_operators", ",", "nil", ",", "nil", ")", "# set the measure period data criteria for all measure period keys", "v1_data_criteria_by_id", "[", "measure_period_key", "]", "=", "measure_criteria", "v1_data_criteria_by_id", "[", "measure_start_key", "]", "=", "measure_criteria", "v1_data_criteria_by_id", "[", "measure_end_key", "]", "=", "measure_criteria", "@measure_period_criteria", "=", "measure_criteria", "end" ]
this method creates V1 data criteria for the measurement period. These data criteria can be referenced properly within the restrictions
[ "this", "method", "creates", "V1", "data", "criteria", "for", "the", "measurement", "period", ".", "These", "data", "criteria", "can", "be", "referenced", "properly", "within", "the", "restrictions" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb#L214-L245
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb
HQMF2.DataCriteriaBaseExtractions.extract_child_criteria
def extract_child_criteria @entry.xpath("./*/cda:outboundRelationship[@typeCode='COMP']/cda:criteriaReference/cda:id", HQMF2::Document::NAMESPACES).collect do |ref| Reference.new(ref).id end.compact end
ruby
def extract_child_criteria @entry.xpath("./*/cda:outboundRelationship[@typeCode='COMP']/cda:criteriaReference/cda:id", HQMF2::Document::NAMESPACES).collect do |ref| Reference.new(ref).id end.compact end
[ "def", "extract_child_criteria", "@entry", ".", "xpath", "(", "\"./*/cda:outboundRelationship[@typeCode='COMP']/cda:criteriaReference/cda:id\"", ",", "HQMF2", "::", "Document", "::", "NAMESPACES", ")", ".", "collect", "do", "|", "ref", "|", "Reference", ".", "new", "(", "ref", ")", ".", "id", "end", ".", "compact", "end" ]
Generate a list of child criterias
[ "Generate", "a", "list", "of", "child", "criterias" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb#L22-L27
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb
HQMF2.DataCriteriaBaseExtractions.all_subset_operators
def all_subset_operators @entry.xpath('./*/cda:excerpt', HQMF2::Document::NAMESPACES).collect do |subset_operator| SubsetOperator.new(subset_operator) end end
ruby
def all_subset_operators @entry.xpath('./*/cda:excerpt', HQMF2::Document::NAMESPACES).collect do |subset_operator| SubsetOperator.new(subset_operator) end end
[ "def", "all_subset_operators", "@entry", ".", "xpath", "(", "'./*/cda:excerpt'", ",", "HQMF2", "::", "Document", "::", "NAMESPACES", ")", ".", "collect", "do", "|", "subset_operator", "|", "SubsetOperator", ".", "new", "(", "subset_operator", ")", "end", "end" ]
Extracts all subset operators contained in the entry xml
[ "Extracts", "all", "subset", "operators", "contained", "in", "the", "entry", "xml" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb#L56-L60
train
projectcypress/health-data-standards
lib/hqmf-parser/1.0/utilities.rb
HQMF1.Utilities.check_nil_conjunction_on_child
def check_nil_conjunction_on_child if (@preconditions.length == 1 && @preconditions.first.conjunction.nil?) bad_precondition = @preconditions.first if (bad_precondition.restrictions.empty? && bad_precondition.subset.nil? && bad_precondition.expression.nil?) @preconditions = @preconditions.first.preconditions #puts "\t FIXED PRECONDITION WITHOUT CONJUNCTION" else puts "\t PRECONDITION WITHOUT CONJUNCTION: Cannot be fixed" end end end
ruby
def check_nil_conjunction_on_child if (@preconditions.length == 1 && @preconditions.first.conjunction.nil?) bad_precondition = @preconditions.first if (bad_precondition.restrictions.empty? && bad_precondition.subset.nil? && bad_precondition.expression.nil?) @preconditions = @preconditions.first.preconditions #puts "\t FIXED PRECONDITION WITHOUT CONJUNCTION" else puts "\t PRECONDITION WITHOUT CONJUNCTION: Cannot be fixed" end end end
[ "def", "check_nil_conjunction_on_child", "if", "(", "@preconditions", ".", "length", "==", "1", "&&", "@preconditions", ".", "first", ".", "conjunction", ".", "nil?", ")", "bad_precondition", "=", "@preconditions", ".", "first", "if", "(", "bad_precondition", ".", "restrictions", ".", "empty?", "&&", "bad_precondition", ".", "subset", ".", "nil?", "&&", "bad_precondition", ".", "expression", ".", "nil?", ")", "@preconditions", "=", "@preconditions", ".", "first", ".", "preconditions", "#puts \"\\t FIXED PRECONDITION WITHOUT CONJUNCTION\"", "else", "puts", "\"\\t PRECONDITION WITHOUT CONJUNCTION: Cannot be fixed\"", "end", "end", "end" ]
Preconditions can have nil conjunctions as part of a DATEDIFF, we want to remove these and warn
[ "Preconditions", "can", "have", "nil", "conjunctions", "as", "part", "of", "a", "DATEDIFF", "we", "want", "to", "remove", "these", "and", "warn" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/1.0/utilities.rb#L41-L51
train
projectcypress/health-data-standards
lib/hqmf-model/document.rb
HQMF.Document.specific_occurrence_source_data_criteria
def specific_occurrence_source_data_criteria(force_sources=nil) return [] if @source_data_criteria.nil? matching = @source_data_criteria.select {|dc| !dc.specific_occurrence.nil?} if force_sources existing = matching.map(&:id) matching.concat @source_data_criteria.select {|dc| !existing.include?(dc.id) && force_sources.include?(dc.id)} end matching end
ruby
def specific_occurrence_source_data_criteria(force_sources=nil) return [] if @source_data_criteria.nil? matching = @source_data_criteria.select {|dc| !dc.specific_occurrence.nil?} if force_sources existing = matching.map(&:id) matching.concat @source_data_criteria.select {|dc| !existing.include?(dc.id) && force_sources.include?(dc.id)} end matching end
[ "def", "specific_occurrence_source_data_criteria", "(", "force_sources", "=", "nil", ")", "return", "[", "]", "if", "@source_data_criteria", ".", "nil?", "matching", "=", "@source_data_criteria", ".", "select", "{", "|", "dc", "|", "!", "dc", ".", "specific_occurrence", ".", "nil?", "}", "if", "force_sources", "existing", "=", "matching", ".", "map", "(", ":id", ")", "matching", ".", "concat", "@source_data_criteria", ".", "select", "{", "|", "dc", "|", "!", "existing", ".", "include?", "(", "dc", ".", "id", ")", "&&", "force_sources", ".", "include?", "(", "dc", ".", "id", ")", "}", "end", "matching", "end" ]
Get the source data criteria that are specific occurrences @return [Array] an array of HQMF::DataCriteria describing the data elements used by the measure that are specific occurrences
[ "Get", "the", "source", "data", "criteria", "that", "are", "specific", "occurrences" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-model/document.rb#L146-L156
train
projectcypress/health-data-standards
lib/hqmf-model/document.rb
HQMF.Document.attributes_for_code
def attributes_for_code(code, code_system) @attributes.find_all { |e| e.send(:code) == code && e.send(:code_obj).send(:system) == code_system } end
ruby
def attributes_for_code(code, code_system) @attributes.find_all { |e| e.send(:code) == code && e.send(:code_obj).send(:system) == code_system } end
[ "def", "attributes_for_code", "(", "code", ",", "code_system", ")", "@attributes", ".", "find_all", "{", "|", "e", "|", "e", ".", "send", "(", ":code", ")", "==", "code", "&&", "e", ".", "send", "(", ":code_obj", ")", ".", "send", "(", ":system", ")", "==", "code_system", "}", "end" ]
Get specific attributes by code. @param [String] code the attribute code @param [String] code_system the attribute code system @return [Array#Attribute] the matching attributes, raises an Exception if not found
[ "Get", "specific", "attributes", "by", "code", "." ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-model/document.rb#L183-L185
train
projectcypress/health-data-standards
lib/hqmf-model/document.rb
HQMF.Document.backfill_patient_characteristics_with_codes
def backfill_patient_characteristics_with_codes(codes) [].concat(self.all_data_criteria).concat(self.source_data_criteria).each do |data_criteria| if (data_criteria.type == :characteristic and !data_criteria.property.nil?) if (codes) value_set = codes[data_criteria.code_list_id] puts "\tno value set for unknown patient characteristic: #{data_criteria.id}" unless value_set else puts "\tno code set to back fill: #{data_criteria.title}" next end if (data_criteria.property == :gender) next if value_set.nil? key = value_set.keys[0] data_criteria.value = HQMF::Coded.new('CD','Administrative Sex',value_set[key].first) else data_criteria.inline_code_list = value_set end elsif (data_criteria.type == :characteristic) if (codes) value_set = codes[data_criteria.code_list_id] if (value_set) # this is looking for a birthdate characteristic that is set as a generic characteristic but points to a loinc code set if (value_set['LOINC'] and value_set['LOINC'].first == '21112-8') data_criteria.definition = 'patient_characteristic_birthdate' end # this is looking for a gender characteristic that is set as a generic characteristic gender_key = (value_set.keys.select {|set| set == 'Administrative Sex' || set == 'AdministrativeSex'}).first if (gender_key and ['M','F'].include? value_set[gender_key].first) data_criteria.definition = 'patient_characteristic_gender' data_criteria.value = HQMF::Coded.new('CD','Gender',value_set[gender_key].first) end end end end end end
ruby
def backfill_patient_characteristics_with_codes(codes) [].concat(self.all_data_criteria).concat(self.source_data_criteria).each do |data_criteria| if (data_criteria.type == :characteristic and !data_criteria.property.nil?) if (codes) value_set = codes[data_criteria.code_list_id] puts "\tno value set for unknown patient characteristic: #{data_criteria.id}" unless value_set else puts "\tno code set to back fill: #{data_criteria.title}" next end if (data_criteria.property == :gender) next if value_set.nil? key = value_set.keys[0] data_criteria.value = HQMF::Coded.new('CD','Administrative Sex',value_set[key].first) else data_criteria.inline_code_list = value_set end elsif (data_criteria.type == :characteristic) if (codes) value_set = codes[data_criteria.code_list_id] if (value_set) # this is looking for a birthdate characteristic that is set as a generic characteristic but points to a loinc code set if (value_set['LOINC'] and value_set['LOINC'].first == '21112-8') data_criteria.definition = 'patient_characteristic_birthdate' end # this is looking for a gender characteristic that is set as a generic characteristic gender_key = (value_set.keys.select {|set| set == 'Administrative Sex' || set == 'AdministrativeSex'}).first if (gender_key and ['M','F'].include? value_set[gender_key].first) data_criteria.definition = 'patient_characteristic_gender' data_criteria.value = HQMF::Coded.new('CD','Gender',value_set[gender_key].first) end end end end end end
[ "def", "backfill_patient_characteristics_with_codes", "(", "codes", ")", "[", "]", ".", "concat", "(", "self", ".", "all_data_criteria", ")", ".", "concat", "(", "self", ".", "source_data_criteria", ")", ".", "each", "do", "|", "data_criteria", "|", "if", "(", "data_criteria", ".", "type", "==", ":characteristic", "and", "!", "data_criteria", ".", "property", ".", "nil?", ")", "if", "(", "codes", ")", "value_set", "=", "codes", "[", "data_criteria", ".", "code_list_id", "]", "puts", "\"\\tno value set for unknown patient characteristic: #{data_criteria.id}\"", "unless", "value_set", "else", "puts", "\"\\tno code set to back fill: #{data_criteria.title}\"", "next", "end", "if", "(", "data_criteria", ".", "property", "==", ":gender", ")", "next", "if", "value_set", ".", "nil?", "key", "=", "value_set", ".", "keys", "[", "0", "]", "data_criteria", ".", "value", "=", "HQMF", "::", "Coded", ".", "new", "(", "'CD'", ",", "'Administrative Sex'", ",", "value_set", "[", "key", "]", ".", "first", ")", "else", "data_criteria", ".", "inline_code_list", "=", "value_set", "end", "elsif", "(", "data_criteria", ".", "type", "==", ":characteristic", ")", "if", "(", "codes", ")", "value_set", "=", "codes", "[", "data_criteria", ".", "code_list_id", "]", "if", "(", "value_set", ")", "# this is looking for a birthdate characteristic that is set as a generic characteristic but points to a loinc code set", "if", "(", "value_set", "[", "'LOINC'", "]", "and", "value_set", "[", "'LOINC'", "]", ".", "first", "==", "'21112-8'", ")", "data_criteria", ".", "definition", "=", "'patient_characteristic_birthdate'", "end", "# this is looking for a gender characteristic that is set as a generic characteristic", "gender_key", "=", "(", "value_set", ".", "keys", ".", "select", "{", "|", "set", "|", "set", "==", "'Administrative Sex'", "||", "set", "==", "'AdministrativeSex'", "}", ")", ".", "first", "if", "(", "gender_key", "and", "[", "'M'", ",", "'F'", "]", ".", "include?", "value_set", "[", "gender_key", "]", ".", "first", ")", "data_criteria", ".", "definition", "=", "'patient_characteristic_gender'", "data_criteria", ".", "value", "=", "HQMF", "::", "Coded", ".", "new", "(", "'CD'", ",", "'Gender'", ",", "value_set", "[", "gender_key", "]", ".", "first", ")", "end", "end", "end", "end", "end", "end" ]
patient characteristics data criteria such as GENDER require looking at the codes to determine if the measure is interested in Males or Females. This process is awkward, and thus is done as a separate step after the document has been converted.
[ "patient", "characteristics", "data", "criteria", "such", "as", "GENDER", "require", "looking", "at", "the", "codes", "to", "determine", "if", "the", "measure", "is", "interested", "in", "Males", "or", "Females", ".", "This", "process", "is", "awkward", "and", "thus", "is", "done", "as", "a", "separate", "step", "after", "the", "document", "has", "been", "converted", "." ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-model/document.rb#L197-L236
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb
HQMF2.DataCriteriaTypeAndDefinitionExtraction.handle_known_template_id
def handle_known_template_id(template_id) case template_id when VARIABLE_TEMPLATE @derivation_operator = HQMF::DataCriteria::INTERSECT if @derivation_operator == HQMF::DataCriteria::XPRODUCT @definition ||= 'derived' @variable = true @negation = false when SATISFIES_ANY_TEMPLATE @definition = HQMF::DataCriteria::SATISFIES_ANY @negation = false when SATISFIES_ALL_TEMPLATE @definition = HQMF::DataCriteria::SATISFIES_ALL @derivation_operator = HQMF::DataCriteria::INTERSECT @negation = false else return false end true end
ruby
def handle_known_template_id(template_id) case template_id when VARIABLE_TEMPLATE @derivation_operator = HQMF::DataCriteria::INTERSECT if @derivation_operator == HQMF::DataCriteria::XPRODUCT @definition ||= 'derived' @variable = true @negation = false when SATISFIES_ANY_TEMPLATE @definition = HQMF::DataCriteria::SATISFIES_ANY @negation = false when SATISFIES_ALL_TEMPLATE @definition = HQMF::DataCriteria::SATISFIES_ALL @derivation_operator = HQMF::DataCriteria::INTERSECT @negation = false else return false end true end
[ "def", "handle_known_template_id", "(", "template_id", ")", "case", "template_id", "when", "VARIABLE_TEMPLATE", "@derivation_operator", "=", "HQMF", "::", "DataCriteria", "::", "INTERSECT", "if", "@derivation_operator", "==", "HQMF", "::", "DataCriteria", "::", "XPRODUCT", "@definition", "||=", "'derived'", "@variable", "=", "true", "@negation", "=", "false", "when", "SATISFIES_ANY_TEMPLATE", "@definition", "=", "HQMF", "::", "DataCriteria", "::", "SATISFIES_ANY", "@negation", "=", "false", "when", "SATISFIES_ALL_TEMPLATE", "@definition", "=", "HQMF", "::", "DataCriteria", "::", "SATISFIES_ALL", "@derivation_operator", "=", "HQMF", "::", "DataCriteria", "::", "INTERSECT", "@negation", "=", "false", "else", "return", "false", "end", "true", "end" ]
Given a template id, modify the variables inside this data criteria to reflect the template
[ "Given", "a", "template", "id", "modify", "the", "variables", "inside", "this", "data", "criteria", "to", "reflect", "the", "template" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb#L36-L54
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb
HQMF2.DataCriteriaTypeAndDefinitionExtraction.extract_information_for_specific_variable
def extract_information_for_specific_variable reference = @entry.at_xpath('./*/cda:outboundRelationship/cda:criteriaReference', HQMF2::Document::NAMESPACES) if reference ref_id = strip_tokens( "#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}") end reference_criteria = @data_criteria_references[ref_id] if ref_id # if the reference is derived, pull from the original variable if reference_criteria && reference_criteria.definition == 'derived' reference_criteria = @data_criteria_references["GROUP_#{ref_id}"] end return unless reference_criteria handle_specific_variable_ref(reference_criteria) end
ruby
def extract_information_for_specific_variable reference = @entry.at_xpath('./*/cda:outboundRelationship/cda:criteriaReference', HQMF2::Document::NAMESPACES) if reference ref_id = strip_tokens( "#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}") end reference_criteria = @data_criteria_references[ref_id] if ref_id # if the reference is derived, pull from the original variable if reference_criteria && reference_criteria.definition == 'derived' reference_criteria = @data_criteria_references["GROUP_#{ref_id}"] end return unless reference_criteria handle_specific_variable_ref(reference_criteria) end
[ "def", "extract_information_for_specific_variable", "reference", "=", "@entry", ".", "at_xpath", "(", "'./*/cda:outboundRelationship/cda:criteriaReference'", ",", "HQMF2", "::", "Document", "::", "NAMESPACES", ")", "if", "reference", "ref_id", "=", "strip_tokens", "(", "\"#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}\"", ")", "end", "reference_criteria", "=", "@data_criteria_references", "[", "ref_id", "]", "if", "ref_id", "# if the reference is derived, pull from the original variable", "if", "reference_criteria", "&&", "reference_criteria", ".", "definition", "==", "'derived'", "reference_criteria", "=", "@data_criteria_references", "[", "\"GROUP_#{ref_id}\"", "]", "end", "return", "unless", "reference_criteria", "handle_specific_variable_ref", "(", "reference_criteria", ")", "end" ]
Extracts information from a reference for a specific
[ "Extracts", "information", "from", "a", "reference", "for", "a", "specific" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb#L73-L87
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb
HQMF2.DataCriteriaTypeAndDefinitionExtraction.handle_specific_variable_ref
def handle_specific_variable_ref(reference_criteria) # if there are no referenced children, then it's a variable representing # a single data criteria, so just reference it if reference_criteria.children_criteria.empty? @children_criteria = [reference_criteria.id] # otherwise pull all the data criteria info from the reference else @field_values = reference_criteria.field_values @temporal_references = reference_criteria.temporal_references @subset_operators = reference_criteria.subset_operators @derivation_operator = reference_criteria.derivation_operator @definition = reference_criteria.definition @description = reference_criteria.description @status = reference_criteria.status @children_criteria = reference_criteria.children_criteria end end
ruby
def handle_specific_variable_ref(reference_criteria) # if there are no referenced children, then it's a variable representing # a single data criteria, so just reference it if reference_criteria.children_criteria.empty? @children_criteria = [reference_criteria.id] # otherwise pull all the data criteria info from the reference else @field_values = reference_criteria.field_values @temporal_references = reference_criteria.temporal_references @subset_operators = reference_criteria.subset_operators @derivation_operator = reference_criteria.derivation_operator @definition = reference_criteria.definition @description = reference_criteria.description @status = reference_criteria.status @children_criteria = reference_criteria.children_criteria end end
[ "def", "handle_specific_variable_ref", "(", "reference_criteria", ")", "# if there are no referenced children, then it's a variable representing", "# a single data criteria, so just reference it", "if", "reference_criteria", ".", "children_criteria", ".", "empty?", "@children_criteria", "=", "[", "reference_criteria", ".", "id", "]", "# otherwise pull all the data criteria info from the reference", "else", "@field_values", "=", "reference_criteria", ".", "field_values", "@temporal_references", "=", "reference_criteria", ".", "temporal_references", "@subset_operators", "=", "reference_criteria", ".", "subset_operators", "@derivation_operator", "=", "reference_criteria", ".", "derivation_operator", "@definition", "=", "reference_criteria", ".", "definition", "@description", "=", "reference_criteria", ".", "description", "@status", "=", "reference_criteria", ".", "status", "@children_criteria", "=", "reference_criteria", ".", "children_criteria", "end", "end" ]
Apply additional information to a specific occurrence's elements from the criteria it references.
[ "Apply", "additional", "information", "to", "a", "specific", "occurrence", "s", "elements", "from", "the", "criteria", "it", "references", "." ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb#L90-L106
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb
HQMF2.DataCriteriaTypeAndDefinitionExtraction.definition_for_nil_entry
def definition_for_nil_entry reference = @entry.at_xpath('./*/cda:outboundRelationship/cda:criteriaReference', HQMF2::Document::NAMESPACES) ref_id = nil unless reference.nil? ref_id = "#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}" end reference_criteria = @data_criteria_references[strip_tokens(ref_id)] unless ref_id.nil? if reference_criteria # we only want to copy the reference criteria definition, status, and code_list_id if this is this is not a grouping criteria (i.e., there are no children) if @children_criteria.blank? @definition = reference_criteria.definition @status = reference_criteria.status if @specific_occurrence @title = reference_criteria.title @description = reference_criteria.description @code_list_id = reference_criteria.code_list_id end else # if this is a grouping data criteria (has children) mark it as derived and only pull title and description from the reference criteria @definition = 'derived' if @specific_occurrence @title = reference_criteria.title @description = reference_criteria.description end end else puts "MISSING_DC_REF: #{ref_id}" unless @variable @definition = 'variable' end end
ruby
def definition_for_nil_entry reference = @entry.at_xpath('./*/cda:outboundRelationship/cda:criteriaReference', HQMF2::Document::NAMESPACES) ref_id = nil unless reference.nil? ref_id = "#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}" end reference_criteria = @data_criteria_references[strip_tokens(ref_id)] unless ref_id.nil? if reference_criteria # we only want to copy the reference criteria definition, status, and code_list_id if this is this is not a grouping criteria (i.e., there are no children) if @children_criteria.blank? @definition = reference_criteria.definition @status = reference_criteria.status if @specific_occurrence @title = reference_criteria.title @description = reference_criteria.description @code_list_id = reference_criteria.code_list_id end else # if this is a grouping data criteria (has children) mark it as derived and only pull title and description from the reference criteria @definition = 'derived' if @specific_occurrence @title = reference_criteria.title @description = reference_criteria.description end end else puts "MISSING_DC_REF: #{ref_id}" unless @variable @definition = 'variable' end end
[ "def", "definition_for_nil_entry", "reference", "=", "@entry", ".", "at_xpath", "(", "'./*/cda:outboundRelationship/cda:criteriaReference'", ",", "HQMF2", "::", "Document", "::", "NAMESPACES", ")", "ref_id", "=", "nil", "unless", "reference", ".", "nil?", "ref_id", "=", "\"#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}\"", "end", "reference_criteria", "=", "@data_criteria_references", "[", "strip_tokens", "(", "ref_id", ")", "]", "unless", "ref_id", ".", "nil?", "if", "reference_criteria", "# we only want to copy the reference criteria definition, status, and code_list_id if this is this is not a grouping criteria (i.e., there are no children)", "if", "@children_criteria", ".", "blank?", "@definition", "=", "reference_criteria", ".", "definition", "@status", "=", "reference_criteria", ".", "status", "if", "@specific_occurrence", "@title", "=", "reference_criteria", ".", "title", "@description", "=", "reference_criteria", ".", "description", "@code_list_id", "=", "reference_criteria", ".", "code_list_id", "end", "else", "# if this is a grouping data criteria (has children) mark it as derived and only pull title and description from the reference criteria", "@definition", "=", "'derived'", "if", "@specific_occurrence", "@title", "=", "reference_criteria", ".", "title", "@description", "=", "reference_criteria", ".", "description", "end", "end", "else", "puts", "\"MISSING_DC_REF: #{ref_id}\"", "unless", "@variable", "@definition", "=", "'variable'", "end", "end" ]
If there is no entry type, extract the entry type from what it references, and extract additional information for specific occurrences. If there are no outbound references, print an error and mark it as variable.
[ "If", "there", "is", "no", "entry", "type", "extract", "the", "entry", "type", "from", "what", "it", "references", "and", "extract", "additional", "information", "for", "specific", "occurrences", ".", "If", "there", "are", "no", "outbound", "references", "print", "an", "error", "and", "mark", "it", "as", "variable", "." ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb#L132-L161
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/document_helpers/doc_utilities.rb
HQMF2.DocumentUtilities.handle_variable
def handle_variable(data_criteria, collapsed_source_data_criteria) if data_criteria.is_derived_specific_occurrence_variable data_criteria.handle_derived_specific_occurrence_variable extract_source_data_criteria(data_criteria) return end tmp_id = data_criteria.id grouper_data_criteria = data_criteria.extract_variable_grouper return unless grouper_data_criteria @data_criteria_references[data_criteria.id] = data_criteria @data_criteria_references[grouper_data_criteria.id] = grouper_data_criteria # create a source data criteria for the grouping data critera we just created sdc = SourceDataCriteriaHelper.strip_non_sc_elements(grouper_data_criteria) @source_data_criteria << sdc # check if the original source has been collapsed when generating the SDC list (we need to reference the collapsed version in the sdc list) if collapsed_source_data_criteria[tmp_id] data_criteria.instance_variable_set(:@source_data_criteria, collapsed_source_data_criteria[tmp_id]) else # check if we need to add _source suffix (most source data criteria are segmented with '_source' suffixes) data_criteria_sdc = find(@source_data_criteria, :id, "#{tmp_id}_source") if data_criteria_sdc data_criteria.instance_variable_set(:@source_data_criteria, data_criteria_sdc.id) data_criteria_sdc.instance_variable_set(:@variable, false) # if it's not a derived data criteria then we may need to strip off temporal references, fields, etc as a new source data criteria elsif !['derived', 'satisfies_any', 'satisfies_all'].include?(data_criteria.definition) extract_source_data_criteria(data_criteria) end end @data_criteria << grouper_data_criteria end
ruby
def handle_variable(data_criteria, collapsed_source_data_criteria) if data_criteria.is_derived_specific_occurrence_variable data_criteria.handle_derived_specific_occurrence_variable extract_source_data_criteria(data_criteria) return end tmp_id = data_criteria.id grouper_data_criteria = data_criteria.extract_variable_grouper return unless grouper_data_criteria @data_criteria_references[data_criteria.id] = data_criteria @data_criteria_references[grouper_data_criteria.id] = grouper_data_criteria # create a source data criteria for the grouping data critera we just created sdc = SourceDataCriteriaHelper.strip_non_sc_elements(grouper_data_criteria) @source_data_criteria << sdc # check if the original source has been collapsed when generating the SDC list (we need to reference the collapsed version in the sdc list) if collapsed_source_data_criteria[tmp_id] data_criteria.instance_variable_set(:@source_data_criteria, collapsed_source_data_criteria[tmp_id]) else # check if we need to add _source suffix (most source data criteria are segmented with '_source' suffixes) data_criteria_sdc = find(@source_data_criteria, :id, "#{tmp_id}_source") if data_criteria_sdc data_criteria.instance_variable_set(:@source_data_criteria, data_criteria_sdc.id) data_criteria_sdc.instance_variable_set(:@variable, false) # if it's not a derived data criteria then we may need to strip off temporal references, fields, etc as a new source data criteria elsif !['derived', 'satisfies_any', 'satisfies_all'].include?(data_criteria.definition) extract_source_data_criteria(data_criteria) end end @data_criteria << grouper_data_criteria end
[ "def", "handle_variable", "(", "data_criteria", ",", "collapsed_source_data_criteria", ")", "if", "data_criteria", ".", "is_derived_specific_occurrence_variable", "data_criteria", ".", "handle_derived_specific_occurrence_variable", "extract_source_data_criteria", "(", "data_criteria", ")", "return", "end", "tmp_id", "=", "data_criteria", ".", "id", "grouper_data_criteria", "=", "data_criteria", ".", "extract_variable_grouper", "return", "unless", "grouper_data_criteria", "@data_criteria_references", "[", "data_criteria", ".", "id", "]", "=", "data_criteria", "@data_criteria_references", "[", "grouper_data_criteria", ".", "id", "]", "=", "grouper_data_criteria", "# create a source data criteria for the grouping data critera we just created", "sdc", "=", "SourceDataCriteriaHelper", ".", "strip_non_sc_elements", "(", "grouper_data_criteria", ")", "@source_data_criteria", "<<", "sdc", "# check if the original source has been collapsed when generating the SDC list (we need to reference the collapsed version in the sdc list)", "if", "collapsed_source_data_criteria", "[", "tmp_id", "]", "data_criteria", ".", "instance_variable_set", "(", ":@source_data_criteria", ",", "collapsed_source_data_criteria", "[", "tmp_id", "]", ")", "else", "# check if we need to add _source suffix (most source data criteria are segmented with '_source' suffixes)", "data_criteria_sdc", "=", "find", "(", "@source_data_criteria", ",", ":id", ",", "\"#{tmp_id}_source\"", ")", "if", "data_criteria_sdc", "data_criteria", ".", "instance_variable_set", "(", ":@source_data_criteria", ",", "data_criteria_sdc", ".", "id", ")", "data_criteria_sdc", ".", "instance_variable_set", "(", ":@variable", ",", "false", ")", "# if it's not a derived data criteria then we may need to strip off temporal references, fields, etc as a new source data criteria", "elsif", "!", "[", "'derived'", ",", "'satisfies_any'", ",", "'satisfies_all'", "]", ".", "include?", "(", "data_criteria", ".", "definition", ")", "extract_source_data_criteria", "(", "data_criteria", ")", "end", "end", "@data_criteria", "<<", "grouper_data_criteria", "end" ]
Create grouper data criteria for encapsulating variable data criteria and update document data criteria list and references map
[ "Create", "grouper", "data", "criteria", "for", "encapsulating", "variable", "data", "criteria", "and", "update", "document", "data", "criteria", "list", "and", "references", "map" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/document_helpers/doc_utilities.rb#L6-L41
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/document_helpers/doc_utilities.rb
HQMF2.DocumentUtilities.complex_coverage
def complex_coverage(data_criteria, check_criteria) same_value = data_criteria.value.nil? || data_criteria.value.try(:to_model).try(:to_json) == check_criteria.value.try(:to_model).try(:to_json) same_field_values = same_field_values_check(data_criteria, check_criteria) same_negation_values = data_criteria.negation_code_list_id.nil? || data_criteria.negation_code_list_id == check_criteria.negation_code_list_id same_value && same_negation_values && same_field_values end
ruby
def complex_coverage(data_criteria, check_criteria) same_value = data_criteria.value.nil? || data_criteria.value.try(:to_model).try(:to_json) == check_criteria.value.try(:to_model).try(:to_json) same_field_values = same_field_values_check(data_criteria, check_criteria) same_negation_values = data_criteria.negation_code_list_id.nil? || data_criteria.negation_code_list_id == check_criteria.negation_code_list_id same_value && same_negation_values && same_field_values end
[ "def", "complex_coverage", "(", "data_criteria", ",", "check_criteria", ")", "same_value", "=", "data_criteria", ".", "value", ".", "nil?", "||", "data_criteria", ".", "value", ".", "try", "(", ":to_model", ")", ".", "try", "(", ":to_json", ")", "==", "check_criteria", ".", "value", ".", "try", "(", ":to_model", ")", ".", "try", "(", ":to_json", ")", "same_field_values", "=", "same_field_values_check", "(", "data_criteria", ",", "check_criteria", ")", "same_negation_values", "=", "data_criteria", ".", "negation_code_list_id", ".", "nil?", "||", "data_criteria", ".", "negation_code_list_id", "==", "check_criteria", ".", "negation_code_list_id", "same_value", "&&", "same_negation_values", "&&", "same_field_values", "end" ]
Check elements that do not already exist; else, if they do, check if those elements are the same in a different, potentially matching, data criteria
[ "Check", "elements", "that", "do", "not", "already", "exist", ";", "else", "if", "they", "do", "check", "if", "those", "elements", "are", "the", "same", "in", "a", "different", "potentially", "matching", "data", "criteria" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/document_helpers/doc_utilities.rb#L107-L117
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb
HQMF2.SpecificOccurrenceAndSource.handle_specific_and_source
def handle_specific_and_source(occurrence_identifier, source_data_criteria_extension, source_data_criteria_root, specific_occurrence_const, specific_occurrence) source_data_criteria = "#{source_data_criteria_extension}_#{source_data_criteria_root}_source" if !occurrence_identifier.blank? # if it doesn't exist, add extracted occurrence to the map # puts "\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}" @occurrences_map[strip_tokens(source_data_criteria)] ||= occurrence_identifier specific_occurrence ||= occurrence_identifier specific_occurrence_const = "#{source_data_criteria}".upcase else # create variable occurrences that do not already exist if @is_variable # puts "\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}" @occurrences_map[strip_tokens(source_data_criteria)] ||= occurrence_identifier end occurrence = @occurrences_map.try(:[], strip_tokens(source_data_criteria)) unless occurrence fail "Could not find occurrence mapping for #{source_data_criteria}, #{source_data_criteria_root}" end # puts "\tUsing #{occurrence} for #{@id}" specific_occurrence ||= occurrence end specific_occurrence = 'A' unless specific_occurrence specific_occurrence_const = source_data_criteria.upcase unless specific_occurrence_const [source_data_criteria, source_data_criteria_root, source_data_criteria_extension, specific_occurrence, specific_occurrence_const] end
ruby
def handle_specific_and_source(occurrence_identifier, source_data_criteria_extension, source_data_criteria_root, specific_occurrence_const, specific_occurrence) source_data_criteria = "#{source_data_criteria_extension}_#{source_data_criteria_root}_source" if !occurrence_identifier.blank? # if it doesn't exist, add extracted occurrence to the map # puts "\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}" @occurrences_map[strip_tokens(source_data_criteria)] ||= occurrence_identifier specific_occurrence ||= occurrence_identifier specific_occurrence_const = "#{source_data_criteria}".upcase else # create variable occurrences that do not already exist if @is_variable # puts "\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}" @occurrences_map[strip_tokens(source_data_criteria)] ||= occurrence_identifier end occurrence = @occurrences_map.try(:[], strip_tokens(source_data_criteria)) unless occurrence fail "Could not find occurrence mapping for #{source_data_criteria}, #{source_data_criteria_root}" end # puts "\tUsing #{occurrence} for #{@id}" specific_occurrence ||= occurrence end specific_occurrence = 'A' unless specific_occurrence specific_occurrence_const = source_data_criteria.upcase unless specific_occurrence_const [source_data_criteria, source_data_criteria_root, source_data_criteria_extension, specific_occurrence, specific_occurrence_const] end
[ "def", "handle_specific_and_source", "(", "occurrence_identifier", ",", "source_data_criteria_extension", ",", "source_data_criteria_root", ",", "specific_occurrence_const", ",", "specific_occurrence", ")", "source_data_criteria", "=", "\"#{source_data_criteria_extension}_#{source_data_criteria_root}_source\"", "if", "!", "occurrence_identifier", ".", "blank?", "# if it doesn't exist, add extracted occurrence to the map", "# puts \"\\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}\"", "@occurrences_map", "[", "strip_tokens", "(", "source_data_criteria", ")", "]", "||=", "occurrence_identifier", "specific_occurrence", "||=", "occurrence_identifier", "specific_occurrence_const", "=", "\"#{source_data_criteria}\"", ".", "upcase", "else", "# create variable occurrences that do not already exist", "if", "@is_variable", "# puts \"\\tSetting #{@source_data_criteria}-#{@source_data_criteria_root} to #{occurrence_identifier}\"", "@occurrences_map", "[", "strip_tokens", "(", "source_data_criteria", ")", "]", "||=", "occurrence_identifier", "end", "occurrence", "=", "@occurrences_map", ".", "try", "(", ":[]", ",", "strip_tokens", "(", "source_data_criteria", ")", ")", "unless", "occurrence", "fail", "\"Could not find occurrence mapping for #{source_data_criteria}, #{source_data_criteria_root}\"", "end", "# puts \"\\tUsing #{occurrence} for #{@id}\"", "specific_occurrence", "||=", "occurrence", "end", "specific_occurrence", "=", "'A'", "unless", "specific_occurrence", "specific_occurrence_const", "=", "source_data_criteria", ".", "upcase", "unless", "specific_occurrence_const", "[", "source_data_criteria", ",", "source_data_criteria_root", ",", "source_data_criteria_extension", ",", "specific_occurrence", ",", "specific_occurrence_const", "]", "end" ]
Handle setting the specific and source instance variables with a given occurrence identifier
[ "Handle", "setting", "the", "specific", "and", "source", "instance", "variables", "with", "a", "given", "occurrence", "identifier" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb#L52-L79
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria.rb
HQMF2.DataCriteria.basic_setup
def basic_setup @status = attr_val('./*/cda:statusCode/@code') @id_xpath = './*/cda:id/@extension' @id = "#{attr_val('./*/cda:id/@extension')}_#{attr_val('./*/cda:id/@root')}" @comments = @entry.xpath("./#{CRITERIA_GLOB}/cda:text/cda:xml/cda:qdmUserComments/cda:item/text()", HQMF2::Document::NAMESPACES).map(&:content) @code_list_xpath = './*/cda:code' @value_xpath = './*/cda:value' @is_derived_specific_occurrence_variable = false simple_extractions = DataCriteriaBaseExtractions.new(@entry) @template_ids = simple_extractions.extract_template_ids @local_variable_name = simple_extractions.extract_local_variable_name @temporal_references = simple_extractions.extract_temporal_references @derivation_operator = simple_extractions.extract_derivation_operator @children_criteria = simple_extractions.extract_child_criteria @subset_operators = simple_extractions.extract_subset_operators @negation, @negation_code_list_id = simple_extractions.extract_negation end
ruby
def basic_setup @status = attr_val('./*/cda:statusCode/@code') @id_xpath = './*/cda:id/@extension' @id = "#{attr_val('./*/cda:id/@extension')}_#{attr_val('./*/cda:id/@root')}" @comments = @entry.xpath("./#{CRITERIA_GLOB}/cda:text/cda:xml/cda:qdmUserComments/cda:item/text()", HQMF2::Document::NAMESPACES).map(&:content) @code_list_xpath = './*/cda:code' @value_xpath = './*/cda:value' @is_derived_specific_occurrence_variable = false simple_extractions = DataCriteriaBaseExtractions.new(@entry) @template_ids = simple_extractions.extract_template_ids @local_variable_name = simple_extractions.extract_local_variable_name @temporal_references = simple_extractions.extract_temporal_references @derivation_operator = simple_extractions.extract_derivation_operator @children_criteria = simple_extractions.extract_child_criteria @subset_operators = simple_extractions.extract_subset_operators @negation, @negation_code_list_id = simple_extractions.extract_negation end
[ "def", "basic_setup", "@status", "=", "attr_val", "(", "'./*/cda:statusCode/@code'", ")", "@id_xpath", "=", "'./*/cda:id/@extension'", "@id", "=", "\"#{attr_val('./*/cda:id/@extension')}_#{attr_val('./*/cda:id/@root')}\"", "@comments", "=", "@entry", ".", "xpath", "(", "\"./#{CRITERIA_GLOB}/cda:text/cda:xml/cda:qdmUserComments/cda:item/text()\"", ",", "HQMF2", "::", "Document", "::", "NAMESPACES", ")", ".", "map", "(", ":content", ")", "@code_list_xpath", "=", "'./*/cda:code'", "@value_xpath", "=", "'./*/cda:value'", "@is_derived_specific_occurrence_variable", "=", "false", "simple_extractions", "=", "DataCriteriaBaseExtractions", ".", "new", "(", "@entry", ")", "@template_ids", "=", "simple_extractions", ".", "extract_template_ids", "@local_variable_name", "=", "simple_extractions", ".", "extract_local_variable_name", "@temporal_references", "=", "simple_extractions", ".", "extract_temporal_references", "@derivation_operator", "=", "simple_extractions", ".", "extract_derivation_operator", "@children_criteria", "=", "simple_extractions", ".", "extract_child_criteria", "@subset_operators", "=", "simple_extractions", ".", "extract_subset_operators", "@negation", ",", "@negation_code_list_id", "=", "simple_extractions", ".", "extract_negation", "end" ]
Handles elments that can be extracted directly from the xml. Utilises the "BaseExtractions" class.
[ "Handles", "elments", "that", "can", "be", "extracted", "directly", "from", "the", "xml", ".", "Utilises", "the", "BaseExtractions", "class", "." ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria.rb#L184-L201
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria.rb
HQMF2.DataCriteria.duplicate_child_info
def duplicate_child_info(child_ref) @title ||= child_ref.title @type ||= child_ref.subset_operators @definition ||= child_ref.definition @status ||= child_ref.status @code_list_id ||= child_ref.code_list_id @temporal_references = child_ref.temporal_references if @temporal_references.empty? @subset_operators ||= child_ref.subset_operators @variable ||= child_ref.variable @value ||= child_ref.value end
ruby
def duplicate_child_info(child_ref) @title ||= child_ref.title @type ||= child_ref.subset_operators @definition ||= child_ref.definition @status ||= child_ref.status @code_list_id ||= child_ref.code_list_id @temporal_references = child_ref.temporal_references if @temporal_references.empty? @subset_operators ||= child_ref.subset_operators @variable ||= child_ref.variable @value ||= child_ref.value end
[ "def", "duplicate_child_info", "(", "child_ref", ")", "@title", "||=", "child_ref", ".", "title", "@type", "||=", "child_ref", ".", "subset_operators", "@definition", "||=", "child_ref", ".", "definition", "@status", "||=", "child_ref", ".", "status", "@code_list_id", "||=", "child_ref", ".", "code_list_id", "@temporal_references", "=", "child_ref", ".", "temporal_references", "if", "@temporal_references", ".", "empty?", "@subset_operators", "||=", "child_ref", ".", "subset_operators", "@variable", "||=", "child_ref", ".", "variable", "@value", "||=", "child_ref", ".", "value", "end" ]
Duplicates information from a child element to this data criteria if none exits. If the duplication requires that come values should be overwritten, do so only in the function calling this.
[ "Duplicates", "information", "from", "a", "child", "element", "to", "this", "data", "criteria", "if", "none", "exits", ".", "If", "the", "duplication", "requires", "that", "come", "values", "should", "be", "overwritten", "do", "so", "only", "in", "the", "function", "calling", "this", "." ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria.rb#L233-L243
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria.rb
HQMF2.DataCriteria.retrieve_field_values_model_for_model
def retrieve_field_values_model_for_model field_values = {} @field_values.each_pair do |id, val| field_values[id] = val.to_model end @code_list_id ||= code_list_id # Model transfers as a field if %w(transfer_to transfer_from).include? @definition field_code_list_id = @code_list_id @code_list_id = nil unless field_code_list_id field_code_list_id = attr_val("./#{CRITERIA_GLOB}/cda:outboundRelationship/#{CRITERIA_GLOB}/cda:value/@valueSet") end field_values[@definition.upcase] = HQMF::Coded.for_code_list(field_code_list_id, title) end return field_values unless field_values.empty? end
ruby
def retrieve_field_values_model_for_model field_values = {} @field_values.each_pair do |id, val| field_values[id] = val.to_model end @code_list_id ||= code_list_id # Model transfers as a field if %w(transfer_to transfer_from).include? @definition field_code_list_id = @code_list_id @code_list_id = nil unless field_code_list_id field_code_list_id = attr_val("./#{CRITERIA_GLOB}/cda:outboundRelationship/#{CRITERIA_GLOB}/cda:value/@valueSet") end field_values[@definition.upcase] = HQMF::Coded.for_code_list(field_code_list_id, title) end return field_values unless field_values.empty? end
[ "def", "retrieve_field_values_model_for_model", "field_values", "=", "{", "}", "@field_values", ".", "each_pair", "do", "|", "id", ",", "val", "|", "field_values", "[", "id", "]", "=", "val", ".", "to_model", "end", "@code_list_id", "||=", "code_list_id", "# Model transfers as a field", "if", "%w(", "transfer_to", "transfer_from", ")", ".", "include?", "@definition", "field_code_list_id", "=", "@code_list_id", "@code_list_id", "=", "nil", "unless", "field_code_list_id", "field_code_list_id", "=", "attr_val", "(", "\"./#{CRITERIA_GLOB}/cda:outboundRelationship/#{CRITERIA_GLOB}/cda:value/@valueSet\"", ")", "end", "field_values", "[", "@definition", ".", "upcase", "]", "=", "HQMF", "::", "Coded", ".", "for_code_list", "(", "field_code_list_id", ",", "title", ")", "end", "return", "field_values", "unless", "field_values", ".", "empty?", "end" ]
Generate the models of the field values
[ "Generate", "the", "models", "of", "the", "field", "values" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria.rb#L246-L264
train
projectcypress/health-data-standards
lib/hqmf-parser/2.0/data_criteria.rb
HQMF2.DataCriteria.retrieve_title_and_description_for_model
def retrieve_title_and_description_for_model # drop "* Value Set" from titles exact_desc = title.split(' ')[0...-3].join(' ') # don't drop anything for patient characterstic titles exact_desc = title if @definition.start_with?('patient_characteristic') && !title.end_with?('Value Set') # remove * Value Set from title title_match = title.match(/(.*) \w+ [Vv]alue [Ss]et/) @title = title_match[1] if title_match && title_match.length > 1 @description = "#{@description}: #{exact_desc}" end
ruby
def retrieve_title_and_description_for_model # drop "* Value Set" from titles exact_desc = title.split(' ')[0...-3].join(' ') # don't drop anything for patient characterstic titles exact_desc = title if @definition.start_with?('patient_characteristic') && !title.end_with?('Value Set') # remove * Value Set from title title_match = title.match(/(.*) \w+ [Vv]alue [Ss]et/) @title = title_match[1] if title_match && title_match.length > 1 @description = "#{@description}: #{exact_desc}" end
[ "def", "retrieve_title_and_description_for_model", "# drop \"* Value Set\" from titles", "exact_desc", "=", "title", ".", "split", "(", "' '", ")", "[", "0", "...", "-", "3", "]", ".", "join", "(", "' '", ")", "# don't drop anything for patient characterstic titles", "exact_desc", "=", "title", "if", "@definition", ".", "start_with?", "(", "'patient_characteristic'", ")", "&&", "!", "title", ".", "end_with?", "(", "'Value Set'", ")", "# remove * Value Set from title", "title_match", "=", "title", ".", "match", "(", "/", "\\w", "/", ")", "@title", "=", "title_match", "[", "1", "]", "if", "title_match", "&&", "title_match", ".", "length", ">", "1", "@description", "=", "\"#{@description}: #{exact_desc}\"", "end" ]
Generate the title and description used when producing the model
[ "Generate", "the", "title", "and", "description", "used", "when", "producing", "the", "model" ]
252d4f0927c513eacde6b9ea41b76faa1423c34b
https://github.com/projectcypress/health-data-standards/blob/252d4f0927c513eacde6b9ea41b76faa1423c34b/lib/hqmf-parser/2.0/data_criteria.rb#L267-L278
train
Shopify/doggy
lib/doggy/model.rb
Doggy.Model.save_local
def save_local ensure_read_only! self.path ||= Doggy.object_root.join("#{prefix}-#{id}.json") File.open(@path, 'w') { |f| f.write(JSON.pretty_generate(to_h)) } end
ruby
def save_local ensure_read_only! self.path ||= Doggy.object_root.join("#{prefix}-#{id}.json") File.open(@path, 'w') { |f| f.write(JSON.pretty_generate(to_h)) } end
[ "def", "save_local", "ensure_read_only!", "self", ".", "path", "||=", "Doggy", ".", "object_root", ".", "join", "(", "\"#{prefix}-#{id}.json\"", ")", "File", ".", "open", "(", "@path", ",", "'w'", ")", "{", "|", "f", "|", "f", ".", "write", "(", "JSON", ".", "pretty_generate", "(", "to_h", ")", ")", "}", "end" ]
class << self
[ "class", "<<", "self" ]
5c5a08698925c26eb1118eae7a81a5ad39dc086f
https://github.com/Shopify/doggy/blob/5c5a08698925c26eb1118eae7a81a5ad39dc086f/lib/doggy/model.rb#L184-L188
train
chef/chef-zero
lib/chef_zero/server.rb
ChefZero.Server.url
def url sch = @options[:ssl] ? "https" : "http" hosts = Array(@options[:host]) @url ||= if hosts.first.include?(":") URI("#{sch}://[#{hosts.first}]:#{port}").to_s else URI("#{sch}://#{hosts.first}:#{port}").to_s end end
ruby
def url sch = @options[:ssl] ? "https" : "http" hosts = Array(@options[:host]) @url ||= if hosts.first.include?(":") URI("#{sch}://[#{hosts.first}]:#{port}").to_s else URI("#{sch}://#{hosts.first}:#{port}").to_s end end
[ "def", "url", "sch", "=", "@options", "[", ":ssl", "]", "?", "\"https\"", ":", "\"http\"", "hosts", "=", "Array", "(", "@options", "[", ":host", "]", ")", "@url", "||=", "if", "hosts", ".", "first", ".", "include?", "(", "\":\"", ")", "URI", "(", "\"#{sch}://[#{hosts.first}]:#{port}\"", ")", ".", "to_s", "else", "URI", "(", "\"#{sch}://#{hosts.first}:#{port}\"", ")", ".", "to_s", "end", "end" ]
The URL for this Chef Zero server. If the given host is an IPV6 address, it is escaped in brackets according to RFC-2732. @see http://www.ietf.org/rfc/rfc2732.txt RFC-2732 @return [String]
[ "The", "URL", "for", "this", "Chef", "Zero", "server", ".", "If", "the", "given", "host", "is", "an", "IPV6", "address", "it", "is", "escaped", "in", "brackets", "according", "to", "RFC", "-", "2732", "." ]
5873d906942770a34f0cf0fed05973ec3240a275
https://github.com/chef/chef-zero/blob/5873d906942770a34f0cf0fed05973ec3240a275/lib/chef_zero/server.rb#L167-L175
train
chef/chef-zero
lib/chef_zero/server.rb
ChefZero.Server.listen
def listen(hosts, port) hosts.each do |host| @server.listen(host, port) end true rescue Errno::EADDRINUSE ChefZero::Log.warn("Port #{port} not available") @server.listeners.each { |l| l.close } @server.listeners.clear false end
ruby
def listen(hosts, port) hosts.each do |host| @server.listen(host, port) end true rescue Errno::EADDRINUSE ChefZero::Log.warn("Port #{port} not available") @server.listeners.each { |l| l.close } @server.listeners.clear false end
[ "def", "listen", "(", "hosts", ",", "port", ")", "hosts", ".", "each", "do", "|", "host", "|", "@server", ".", "listen", "(", "host", ",", "port", ")", "end", "true", "rescue", "Errno", "::", "EADDRINUSE", "ChefZero", "::", "Log", ".", "warn", "(", "\"Port #{port} not available\"", ")", "@server", ".", "listeners", ".", "each", "{", "|", "l", "|", "l", ".", "close", "}", "@server", ".", "listeners", ".", "clear", "false", "end" ]
Start a Chef Zero server in a forked process. This method returns the PID to the forked process. @param [Fixnum] wait the number of seconds to wait for the server to start @return [Thread] the thread the background process is running in
[ "Start", "a", "Chef", "Zero", "server", "in", "a", "forked", "process", ".", "This", "method", "returns", "the", "PID", "to", "the", "forked", "process", "." ]
5873d906942770a34f0cf0fed05973ec3240a275
https://github.com/chef/chef-zero/blob/5873d906942770a34f0cf0fed05973ec3240a275/lib/chef_zero/server.rb#L270-L280
train
chef/chef-zero
lib/chef_zero/server.rb
ChefZero.Server.stop
def stop(wait = 5) if @running @server.shutdown if @server @thread.join(wait) if @thread end rescue Timeout::Error if @thread ChefZero::Log.error("Chef Zero did not stop within #{wait} seconds! Killing...") @thread.kill SocketlessServerMap.deregister(port) end ensure @server = nil @thread = nil end
ruby
def stop(wait = 5) if @running @server.shutdown if @server @thread.join(wait) if @thread end rescue Timeout::Error if @thread ChefZero::Log.error("Chef Zero did not stop within #{wait} seconds! Killing...") @thread.kill SocketlessServerMap.deregister(port) end ensure @server = nil @thread = nil end
[ "def", "stop", "(", "wait", "=", "5", ")", "if", "@running", "@server", ".", "shutdown", "if", "@server", "@thread", ".", "join", "(", "wait", ")", "if", "@thread", "end", "rescue", "Timeout", "::", "Error", "if", "@thread", "ChefZero", "::", "Log", ".", "error", "(", "\"Chef Zero did not stop within #{wait} seconds! Killing...\"", ")", "@thread", ".", "kill", "SocketlessServerMap", ".", "deregister", "(", "port", ")", "end", "ensure", "@server", "=", "nil", "@thread", "=", "nil", "end" ]
Gracefully stop the Chef Zero server. @param [Fixnum] wait the number of seconds to wait before raising force-terminating the server
[ "Gracefully", "stop", "the", "Chef", "Zero", "server", "." ]
5873d906942770a34f0cf0fed05973ec3240a275
https://github.com/chef/chef-zero/blob/5873d906942770a34f0cf0fed05973ec3240a275/lib/chef_zero/server.rb#L358-L372
train
chef/chef-zero
lib/chef_zero/rest_base.rb
ChefZero.RestBase.json_response
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
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
[ "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" ]
Serializes `data` to JSON and returns an Array with the response code, HTTP headers and JSON body. @param [Fixnum] response_code HTTP response code @param [Hash] data The data for the response body as a Hash @param [Hash] options @option options [Hash] :headers (see #already_json_response) @option options [Boolean] :pretty (true) Pretty-format the JSON @option options [Fixnum] :request_version (see #already_json_response) @option options [Fixnum] :response_version (see #already_json_response) @return (see #already_json_response)
[ "Serializes", "data", "to", "JSON", "and", "returns", "an", "Array", "with", "the", "response", "code", "HTTP", "headers", "and", "JSON", "body", "." ]
5873d906942770a34f0cf0fed05973ec3240a275
https://github.com/chef/chef-zero/blob/5873d906942770a34f0cf0fed05973ec3240a275/lib/chef_zero/rest_base.rb#L223-L228
train
chef/chef-zero
lib/chef_zero/rest_base.rb
ChefZero.RestBase.already_json_response
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
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
[ "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" ]
Returns an Array with the response code, HTTP headers, and JSON body. @param [Fixnum] response_code The HTTP response code @param [String] json_text The JSON body for the response @param [Hash] options @option options [Hash] :headers ({}) HTTP headers (may override default headers) @option options [Fixnum] :request_version (0) Request API version @option options [Fixnum] :response_version (0) Response API version @return [Array(Fixnum, Hash{String => String}, String)]
[ "Returns", "an", "Array", "with", "the", "response", "code", "HTTP", "headers", "and", "JSON", "body", "." ]
5873d906942770a34f0cf0fed05973ec3240a275
https://github.com/chef/chef-zero/blob/5873d906942770a34f0cf0fed05973ec3240a275/lib/chef_zero/rest_base.rb#L255-L270
train
chef/chef-zero
lib/chef_zero/rest_base.rb
ChefZero.RestBase.build_uri
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
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
[ "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" ]
To be called from inside rest endpoints
[ "To", "be", "called", "from", "inside", "rest", "endpoints" ]
5873d906942770a34f0cf0fed05973ec3240a275
https://github.com/chef/chef-zero/blob/5873d906942770a34f0cf0fed05973ec3240a275/lib/chef_zero/rest_base.rb#L273-L284
train
forward3d/rbhive
lib/rbhive/t_c_l_i_connection.rb
RBHive.TCLIConnection.parse_sasl_params
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
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
[ "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" ]
Processes SASL connection params and returns a hash with symbol keys or a nil
[ "Processes", "SASL", "connection", "params", "and", "returns", "a", "hash", "with", "symbol", "keys", "or", "a", "nil" ]
a630b57332f2face03501da3ecad2905c78056fa
https://github.com/forward3d/rbhive/blob/a630b57332f2face03501da3ecad2905c78056fa/lib/rbhive/t_c_l_i_connection.rb#L135-L144
train
forward3d/rbhive
lib/rbhive/t_c_l_i_connection.rb
RBHive.TCLIConnection.async_state
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
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
[ "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" ]
Map states to symbols
[ "Map", "states", "to", "symbols" ]
a630b57332f2face03501da3ecad2905c78056fa
https://github.com/forward3d/rbhive/blob/a630b57332f2face03501da3ecad2905c78056fa/lib/rbhive/t_c_l_i_connection.rb#L237-L264
train
forward3d/rbhive
lib/rbhive/t_c_l_i_connection.rb
RBHive.TCLIConnection.async_fetch
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
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
[ "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" ]
Async fetch results from an async execute
[ "Async", "fetch", "results", "from", "an", "async", "execute" ]
a630b57332f2face03501da3ecad2905c78056fa
https://github.com/forward3d/rbhive/blob/a630b57332f2face03501da3ecad2905c78056fa/lib/rbhive/t_c_l_i_connection.rb#L267-L275
train
forward3d/rbhive
lib/rbhive/t_c_l_i_connection.rb
RBHive.TCLIConnection.fetch_rows
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
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
[ "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" ]
Pull rows from the query result
[ "Pull", "rows", "from", "the", "query", "result" ]
a630b57332f2face03501da3ecad2905c78056fa
https://github.com/forward3d/rbhive/blob/a630b57332f2face03501da3ecad2905c78056fa/lib/rbhive/t_c_l_i_connection.rb#L300-L306
train
forward3d/rbhive
lib/rbhive/t_c_l_i_connection.rb
RBHive.TCLIConnection.raise_error_if_failed!
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
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
[ "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" ]
Raises an exception if given operation result is a failure
[ "Raises", "an", "exception", "if", "given", "operation", "result", "is", "a", "failure" ]
a630b57332f2face03501da3ecad2905c78056fa
https://github.com/forward3d/rbhive/blob/a630b57332f2face03501da3ecad2905c78056fa/lib/rbhive/t_c_l_i_connection.rb#L433-L437
train
heroku/legacy-cli
lib/heroku/command/addons.rb
Heroku::Command.Addons.parse_options
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
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
[ "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" ]
this will clean up when we officially deprecate
[ "this", "will", "clean", "up", "when", "we", "officially", "deprecate" ]
6f18521a258394bfb79e6b36f7160ad8559a8e16
https://github.com/heroku/legacy-cli/blob/6f18521a258394bfb79e6b36f7160ad8559a8e16/lib/heroku/command/addons.rb#L414-L444
train
heroku/legacy-cli
lib/heroku/helpers.rb
Heroku.Helpers.line_formatter
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
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
[ "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" ]
produces a printf formatter line for an array of items if an individual line item is an array, it will create columns that are lined-up line_formatter(["foo", "barbaz"]) # => "%-6s" line_formatter(["foo", "barbaz"], ["bar", "qux"]) # => "%-3s %-6s"
[ "produces", "a", "printf", "formatter", "line", "for", "an", "array", "of", "items", "if", "an", "individual", "line", "item", "is", "an", "array", "it", "will", "create", "columns", "that", "are", "lined", "-", "up" ]
6f18521a258394bfb79e6b36f7160ad8559a8e16
https://github.com/heroku/legacy-cli/blob/6f18521a258394bfb79e6b36f7160ad8559a8e16/lib/heroku/helpers.rb#L403-L415
train
randym/axlsx
lib/axlsx/drawing/str_data.rb
Axlsx.StrData.data=
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
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
[ "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" ]
creates a new StrVal object @option options [Array] :data @option options [String] :tag_name Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types. @param [Array] values An array of cells or values.
[ "creates", "a", "new", "StrVal", "object" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/str_data.rb#L22-L28
train
randym/axlsx
lib/axlsx/workbook/worksheet/pivot_table.rb
Axlsx.PivotTable.relationships
def relationships r = Relationships.new r << Relationship.new(cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, "../#{cache_definition.pn}") r end
ruby
def relationships r = Relationships.new r << Relationship.new(cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, "../#{cache_definition.pn}") r end
[ "def", "relationships", "r", "=", "Relationships", ".", "new", "r", "<<", "Relationship", ".", "new", "(", "cache_definition", ",", "PIVOT_TABLE_CACHE_DEFINITION_R", ",", "\"../#{cache_definition.pn}\"", ")", "r", "end" ]
The relationships for this pivot table. @return [Relationships]
[ "The", "relationships", "for", "this", "pivot", "table", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/pivot_table.rb#L161-L165
train
randym/axlsx
lib/axlsx/workbook/worksheet/data_bar.rb
Axlsx.DataBar.color=
def color=(v) @color = v if v.is_a? Color self.color.rgb = v if v.is_a? String @color end
ruby
def color=(v) @color = v if v.is_a? Color self.color.rgb = v if v.is_a? String @color end
[ "def", "color", "=", "(", "v", ")", "@color", "=", "v", "if", "v", ".", "is_a?", "Color", "self", ".", "color", ".", "rgb", "=", "v", "if", "v", ".", "is_a?", "String", "@color", "end" ]
Sets the color for the data bars. @param [Color|String] v The color object, or rgb string value to apply
[ "Sets", "the", "color", "for", "the", "data", "bars", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/data_bar.rb#L100-L104
train
randym/axlsx
lib/axlsx/workbook/worksheet/data_bar.rb
Axlsx.DataBar.to_xml_string
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
def to_xml_string(str="") serialized_tag('dataBar', str) do value_objects.to_xml_string(str) self.color.to_xml_string(str) end end
[ "def", "to_xml_string", "(", "str", "=", "\"\"", ")", "serialized_tag", "(", "'dataBar'", ",", "str", ")", "do", "value_objects", ".", "to_xml_string", "(", "str", ")", "self", ".", "color", ".", "to_xml_string", "(", "str", ")", "end", "end" ]
Serialize this object to an xml string @param [String] str @return [String]
[ "Serialize", "this", "object", "to", "an", "xml", "string" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/data_bar.rb#L109-L114
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.serialize
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
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
[ "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" ]
Serialize your workbook to disk as an xlsx document. @param [String] output The name of the file you want to serialize your package to @param [Boolean] confirm_valid Validate the package prior to serialization. @return [Boolean] False if confirm_valid and validation errors exist. True if the package was serialized @note A tremendous amount of effort has gone into ensuring that you cannot create invalid xlsx documents. confirm_valid should be used in the rare case that you cannot open the serialized file. @see Package#validate @example # This is how easy it is to create a valid xlsx file. Of course you might want to add a sheet or two, and maybe some data, styles and charts. # Take a look at the README for an example of how to do it! #serialize to a file p = Axlsx::Package.new # ......add cool stuff to your workbook...... p.serialize("example.xlsx") # Serialize to a stream s = p.to_stream() File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
[ "Serialize", "your", "workbook", "to", "disk", "as", "an", "xlsx", "document", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L101-L108
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.to_stream
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
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
[ "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" ]
Serialize your workbook to a StringIO instance @param [Boolean] confirm_valid Validate the package prior to serialization. @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not.
[ "Serialize", "your", "workbook", "to", "a", "StringIO", "instance" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L114-L121
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.write_parts
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
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
[ "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" ]
Writes the package parts to a zip archive. @param [Zip::OutputStream] zip @return [Zip::OutputStream]
[ "Writes", "the", "package", "parts", "to", "a", "zip", "archive", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L161-L174
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.parts
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
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
[ "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" ]
The parts of a package @return [Array] An array of hashes that define the entry, document and schema for each part of the package. @private
[ "The", "parts", "of", "a", "package" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L195-L248
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.validate_single_doc
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
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
[ "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" ]
Performs xsd validation for a signle document @param [String] schema path to the xsd schema to be used in validation. @param [String] doc The xml text to be validated @return [Array] An array of all validation errors encountered. @private
[ "Performs", "xsd", "validation", "for", "a", "signle", "document" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L256-L264
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.content_types
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
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
[ "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" ]
Appends override objects for drawings, charts, and sheets as they exist in your workbook to the default content types. @return [ContentType] @private
[ "Appends", "override", "objects", "for", "drawings", "charts", "and", "sheets", "as", "they", "exist", "in", "your", "workbook", "to", "the", "default", "content", "types", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L269-L324
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.base_content_types
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
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
[ "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" ]
Creates the minimum content types for generating a valid xlsx document. @return [ContentType] @private
[ "Creates", "the", "minimum", "content", "types", "for", "generating", "a", "valid", "xlsx", "document", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L329-L339
train
randym/axlsx
lib/axlsx/package.rb
Axlsx.Package.relationships
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
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
[ "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" ]
Creates the relationships required for a valid xlsx document @return [Relationships] @private
[ "Creates", "the", "relationships", "required", "for", "a", "valid", "xlsx", "document" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/package.rb#L344-L351
train
randym/axlsx
lib/axlsx/drawing/pic.rb
Axlsx.Pic.hyperlink=
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
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
[ "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" ]
sets or updates a hyperlink for this image. @param [String] v The href value for the hyper link @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value.
[ "sets", "or", "updates", "a", "hyperlink", "for", "this", "image", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/pic.rb#L62-L72
train
randym/axlsx
lib/axlsx/drawing/pic.rb
Axlsx.Pic.end_at
def end_at(x, y=nil) use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor) @anchor.end_at x, y @anchor.to end
ruby
def end_at(x, y=nil) use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor) @anchor.end_at x, y @anchor.to end
[ "def", "end_at", "(", "x", ",", "y", "=", "nil", ")", "use_two_cell_anchor", "unless", "@anchor", ".", "is_a?", "(", "TwoCellAnchor", ")", "@anchor", ".", "end_at", "x", ",", "y", "@anchor", ".", "to", "end" ]
noop if not using a two cell anchor @param [Integer] x The column @param [Integer] y The row @return [Marker]
[ "noop", "if", "not", "using", "a", "two", "cell", "anchor" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/pic.rb#L159-L163
train
randym/axlsx
lib/axlsx/drawing/pic.rb
Axlsx.Pic.use_one_cell_anchor
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
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
[ "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" ]
Changes the anchor to a one cell anchor.
[ "Changes", "the", "anchor", "to", "a", "one", "cell", "anchor", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/pic.rb#L190-L194
train
randym/axlsx
lib/axlsx/drawing/pic.rb
Axlsx.Pic.use_two_cell_anchor
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
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
[ "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" ]
changes the anchor type to a two cell anchor
[ "changes", "the", "anchor", "type", "to", "a", "two", "cell", "anchor" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/pic.rb#L197-L201
train
randym/axlsx
lib/axlsx/drawing/pic.rb
Axlsx.Pic.swap_anchor
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
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
[ "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" ]
refactoring of swapping code, law of demeter be damned!
[ "refactoring", "of", "swapping", "code", "law", "of", "demeter", "be", "damned!" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/pic.rb#L204-L209
train
randym/axlsx
lib/axlsx/workbook/worksheet/color_scale.rb
Axlsx.ColorScale.add
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
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
[ "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" ]
creates a new ColorScale object. @see Cfvo @see Color @example color_scale = Axlsx::ColorScale.new({:type => :num, :val => 0.55, :color => 'fff7696c'}) adds a new cfvo / color pair to the color scale and returns a hash containing a reference to the newly created cfvo and color objects so you can alter the default properties. @return [Hash] a hash with :cfvo and :color keys referencing the newly added objects. @param [Hash] options options for the new cfvo and color objects @option [Symbol] type The type of cfvo you to add @option [Any] val The value of the cfvo to add @option [String] The rgb color for the cfvo
[ "creates", "a", "new", "ColorScale", "object", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/color_scale.rb#L70-L74
train
randym/axlsx
lib/axlsx/workbook/worksheet/color_scale.rb
Axlsx.ColorScale.to_xml_string
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
def to_xml_string(str = '') str << '<colorScale>' value_objects.to_xml_string(str) colors.each { |color| color.to_xml_string(str) } str << '</colorScale>' end
[ "def", "to_xml_string", "(", "str", "=", "''", ")", "str", "<<", "'<colorScale>'", "value_objects", ".", "to_xml_string", "(", "str", ")", "colors", ".", "each", "{", "|", "color", "|", "color", ".", "to_xml_string", "(", "str", ")", "}", "str", "<<", "'</colorScale>'", "end" ]
Serialize this color_scale object data to an xml string @param [String] str @return [String]
[ "Serialize", "this", "color_scale", "object", "data", "to", "an", "xml", "string" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/color_scale.rb#L88-L93
train
randym/axlsx
lib/axlsx/workbook/worksheet/color_scale.rb
Axlsx.ColorScale.initialize_default_cfvos
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
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
[ "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" ]
There has got to be cleaner way of merging these arrays.
[ "There", "has", "got", "to", "be", "cleaner", "way", "of", "merging", "these", "arrays", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/color_scale.rb#L97-L108
train
randym/axlsx
lib/axlsx/drawing/axes.rb
Axlsx.Axes.add_axis
def add_axis(name, axis_class) axis = axis_class.new set_cross_axis(axis) axes << [name, axis] end
ruby
def add_axis(name, axis_class) axis = axis_class.new set_cross_axis(axis) axes << [name, axis] end
[ "def", "add_axis", "(", "name", ",", "axis_class", ")", "axis", "=", "axis_class", ".", "new", "set_cross_axis", "(", "axis", ")", "axes", "<<", "[", "name", ",", "axis", "]", "end" ]
Adds an axis to the collection @param [Symbol] name The name of the axis @param [Axis] axis_class The axis class to generate
[ "Adds", "an", "axis", "to", "the", "collection" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/axes.rb#L44-L48
train
randym/axlsx
lib/axlsx/workbook/shared_strings_table.rb
Axlsx.SharedStringsTable.to_xml_string
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
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
[ "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" ]
Creates a new Shared Strings Table agains an array of cells @param [Array] cells This is an array of all of the cells in the workbook @param [Symbol] xml_space The xml:space behavior for the shared string table. Serializes the object @param [String] str @return [String]
[ "Creates", "a", "new", "Shared", "Strings", "Table", "agains", "an", "array", "of", "cells" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/shared_strings_table.rb#L49-L54
train
randym/axlsx
lib/axlsx/workbook/shared_strings_table.rb
Axlsx.SharedStringsTable.resolve
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
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
[ "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" ]
Interate over all of the cells in the array. if our unique cells array does not contain a sharable cell, add the cell to our unique cells array and set the ssti attribute on the index of this cell in the shared strings table if a sharable cell already exists in our unique_cells array, set the ssti attribute of the cell and move on. @return [Array] unique cells
[ "Interate", "over", "all", "of", "the", "cells", "in", "the", "array", ".", "if", "our", "unique", "cells", "array", "does", "not", "contain", "a", "sharable", "cell", "add", "the", "cell", "to", "our", "unique", "cells", "array", "and", "set", "the", "ssti", "attribute", "on", "the", "index", "of", "this", "cell", "in", "the", "shared", "strings", "table", "if", "a", "sharable", "cell", "already", "exists", "in", "our", "unique_cells", "array", "set", "the", "ssti", "attribute", "of", "the", "cell", "and", "move", "on", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/shared_strings_table.rb#L63-L75
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb
Axlsx.WorksheetHyperlinks.to_xml_string
def to_xml_string(str='') return if empty? str << '<hyperlinks>' each { |hyperlink| hyperlink.to_xml_string(str) } str << '</hyperlinks>' end
ruby
def to_xml_string(str='') return if empty? str << '<hyperlinks>' each { |hyperlink| hyperlink.to_xml_string(str) } str << '</hyperlinks>' end
[ "def", "to_xml_string", "(", "str", "=", "''", ")", "return", "if", "empty?", "str", "<<", "'<hyperlinks>'", "each", "{", "|", "hyperlink", "|", "hyperlink", ".", "to_xml_string", "(", "str", ")", "}", "str", "<<", "'</hyperlinks>'", "end" ]
seralize the collection of hyperlinks @return [String]
[ "seralize", "the", "collection", "of", "hyperlinks" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb#L31-L36
train
randym/axlsx
lib/axlsx/workbook/workbook.rb
Axlsx.Workbook.sheet_by_name
def sheet_by_name(name) index = @worksheets.index { |sheet| sheet.name == name } @worksheets[index] if index end
ruby
def sheet_by_name(name) index = @worksheets.index { |sheet| sheet.name == name } @worksheets[index] if index end
[ "def", "sheet_by_name", "(", "name", ")", "index", "=", "@worksheets", ".", "index", "{", "|", "sheet", "|", "sheet", ".", "name", "==", "name", "}", "@worksheets", "[", "index", "]", "if", "index", "end" ]
A quick helper to retrive a worksheet by name @param [String] name The name of the sheet you are looking for @return [Worksheet] The sheet found, or nil
[ "A", "quick", "helper", "to", "retrive", "a", "worksheet", "by", "name" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/workbook.rb#L195-L198
train
randym/axlsx
lib/axlsx/workbook/workbook.rb
Axlsx.Workbook.insert_worksheet
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
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
[ "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" ]
inserts a worksheet into this workbook at the position specified. It the index specified is out of range, the worksheet will be added to the end of the worksheets collection @return [Worksheet] @param index The zero based position to insert the newly created worksheet @param [Hash] options Options to pass into the worksheed during initialization. @option options [String] name The name of the worksheet @option options [Hash] page_margins The page margins for the worksheet
[ "inserts", "a", "worksheet", "into", "this", "workbook", "at", "the", "position", "specified", ".", "It", "the", "index", "specified", "is", "out", "of", "range", "the", "worksheet", "will", "be", "added", "to", "the", "end", "of", "the", "worksheets", "collection" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/workbook.rb#L263-L269
train
randym/axlsx
lib/axlsx/workbook/workbook.rb
Axlsx.Workbook.relationships
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
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
[ "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" ]
The workbook relationships. This is managed automatically by the workbook @return [Relationships]
[ "The", "workbook", "relationships", ".", "This", "is", "managed", "automatically", "by", "the", "workbook" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/workbook.rb#L301-L314
train
randym/axlsx
lib/axlsx/workbook/workbook.rb
Axlsx.Workbook.[]
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
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
[ "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" ]
returns a range of cells in a worksheet @param [String] cell_def The excel style reference defining the worksheet and cells. The range must specify the sheet to retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell. @return [Cell, Array]
[ "returns", "a", "range", "of", "cells", "in", "a", "worksheet" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/workbook.rb#L344-L349
train
randym/axlsx
lib/axlsx/workbook/workbook.rb
Axlsx.Workbook.to_xml_string
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
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
[ "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" ]
Serialize the workbook @param [String] str @return [String]
[ "Serialize", "the", "workbook" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/workbook.rb#L354-L376
train
randym/axlsx
lib/axlsx/workbook/worksheet/page_margins.rb
Axlsx.PageMargins.set
def set(margins) margins.select do |k, v| next unless [:left, :right, :top, :bottom, :header, :footer].include? k send("#{k}=", v) end end
ruby
def set(margins) margins.select do |k, v| next unless [:left, :right, :top, :bottom, :header, :footer].include? k send("#{k}=", v) end end
[ "def", "set", "(", "margins", ")", "margins", ".", "select", "do", "|", "k", ",", "v", "|", "next", "unless", "[", ":left", ",", ":right", ",", ":top", ",", ":bottom", ",", ":header", ",", ":footer", "]", ".", "include?", "k", "send", "(", "\"#{k}=\"", ",", "v", ")", "end", "end" ]
Set some or all margins at once. @param [Hash] margins the margins to set (possible keys are :left, :right, :top, :bottom, :header and :footer).
[ "Set", "some", "or", "all", "margins", "at", "once", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/page_margins.rb#L68-L73
train
randym/axlsx
lib/axlsx/drawing/marker.rb
Axlsx.Marker.coord
def coord(col, row=0) coordinates = parse_coord_args(col, row) self.col = coordinates[0] self.row = coordinates[1] end
ruby
def coord(col, row=0) coordinates = parse_coord_args(col, row) self.col = coordinates[0] self.row = coordinates[1] end
[ "def", "coord", "(", "col", ",", "row", "=", "0", ")", "coordinates", "=", "parse_coord_args", "(", "col", ",", "row", ")", "self", ".", "col", "=", "coordinates", "[", "0", "]", "self", ".", "row", "=", "coordinates", "[", "1", "]", "end" ]
shortcut to set the column, row position for this marker @param col the column for the marker, a Cell object or a string reference like "B7" or an Array. @param row the row of the marker. This is ignored if the col parameter is a Cell or String or Array.
[ "shortcut", "to", "set", "the", "column", "row", "position", "for", "this", "marker" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/marker.rb#L50-L54
train
randym/axlsx
lib/axlsx/drawing/marker.rb
Axlsx.Marker.parse_coord_args
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
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
[ "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" ]
handles multiple inputs for setting the position of a marker @see Chart#start_at
[ "handles", "multiple", "inputs", "for", "setting", "the", "position", "of", "a", "marker" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/marker.rb#L68-L79
train
randym/axlsx
lib/axlsx/workbook/worksheet/comments.rb
Axlsx.Comments.add_comment
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
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
[ "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" ]
Creates a new Comments object @param [Worksheet] worksheet The sheet that these comments belong to. Adds a new comment to the worksheet that owns these comments. @note the author, text and ref options are required @option options [String] author The name of the author for this comment @option options [String] text The text for this comment @option options [Stirng|Cell] ref The cell that this comment is attached to.
[ "Creates", "a", "new", "Comments", "object" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/comments.rb#L41-L48
train
randym/axlsx
lib/axlsx/workbook/worksheet/rich_text_run.rb
Axlsx.RichTextRun.autowidth
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
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
[ "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" ]
Tries to work out the width of the longest line in the run @param [Array] widtharray this array is populated with the widths of each line in the run. @return [Array]
[ "Tries", "to", "work", "out", "the", "width", "of", "the", "longest", "line", "in", "the", "run" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/rich_text_run.rb#L163-L179
train
randym/axlsx
lib/axlsx/workbook/worksheet/rich_text_run.rb
Axlsx.RichTextRun.to_xml_string
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
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
[ "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" ]
Serializes the RichTextRun @param [String] str @return [String]
[ "Serializes", "the", "RichTextRun" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/rich_text_run.rb#L191-L209
train
randym/axlsx
lib/axlsx/workbook/worksheet/rich_text_run.rb
Axlsx.RichTextRun.string_width
def string_width(string, font_size) font_scale = font_size / 10.0 string.count(Worksheet::THIN_CHARS) * font_scale end
ruby
def string_width(string, font_size) font_scale = font_size / 10.0 string.count(Worksheet::THIN_CHARS) * font_scale end
[ "def", "string_width", "(", "string", ",", "font_size", ")", "font_scale", "=", "font_size", "/", "10.0", "string", ".", "count", "(", "Worksheet", "::", "THIN_CHARS", ")", "*", "font_scale", "end" ]
Returns the width of a string according to the current style This is still not perfect... - scaling is not linear as font sizes increase
[ "Returns", "the", "width", "of", "a", "string", "according", "to", "the", "current", "style", "This", "is", "still", "not", "perfect", "...", "-", "scaling", "is", "not", "linear", "as", "font", "sizes", "increase" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/rich_text_run.rb#L216-L219
train
randym/axlsx
lib/axlsx/workbook/worksheet/rich_text_run.rb
Axlsx.RichTextRun.font_size
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
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
[ "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" ]
we scale the font size if bold style is applied to either the style font or the cell itself. Yes, it is a bit of a hack, but it is much better than using imagemagick and loading metrics for every character.
[ "we", "scale", "the", "font", "size", "if", "bold", "style", "is", "applied", "to", "either", "the", "style", "font", "or", "the", "cell", "itself", ".", "Yes", "it", "is", "a", "bit", "of", "a", "hack", "but", "it", "is", "much", "better", "than", "using", "imagemagick", "and", "loading", "metrics", "for", "every", "character", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/rich_text_run.rb#L224-L228
train
randym/axlsx
lib/axlsx/stylesheet/gradient_fill.rb
Axlsx.GradientFill.validate_format_percentage
def validate_format_percentage(name, value) DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0} end
ruby
def validate_format_percentage(name, value) DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0} end
[ "def", "validate_format_percentage", "(", "name", ",", "value", ")", "DataTypeValidator", ".", "validate", "name", ",", "Float", ",", "value", ",", "lambda", "{", "|", "arg", "|", "arg", ">=", "0.0", "&&", "arg", "<=", "1.0", "}", "end" ]
validates that the value provided is between 0.0 and 1.0
[ "validates", "that", "the", "value", "provided", "is", "between", "0", ".", "0", "and", "1", ".", "0" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/stylesheet/gradient_fill.rb#L88-L90
train
randym/axlsx
lib/axlsx/content_type/abstract_content_type.rb
Axlsx.AbstractContentType.to_xml_string
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
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
[ "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" ]
Serialize the contenty type to xml
[ "Serialize", "the", "contenty", "type", "to", "xml" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/content_type/abstract_content_type.rb#L25-L29
train
randym/axlsx
lib/axlsx/workbook/worksheet/data_validations.rb
Axlsx.DataValidations.to_xml_string
def to_xml_string(str = "") return if empty? str << "<dataValidations count='#{size}'>" each { |item| item.to_xml_string(str) } str << '</dataValidations>' end
ruby
def to_xml_string(str = "") return if empty? str << "<dataValidations count='#{size}'>" each { |item| item.to_xml_string(str) } str << '</dataValidations>' end
[ "def", "to_xml_string", "(", "str", "=", "\"\"", ")", "return", "if", "empty?", "str", "<<", "\"<dataValidations count='#{size}'>\"", "each", "{", "|", "item", "|", "item", ".", "to_xml_string", "(", "str", ")", "}", "str", "<<", "'</dataValidations>'", "end" ]
serialize the conditional formattings
[ "serialize", "the", "conditional", "formattings" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/data_validations.rb#L18-L23
train
randym/axlsx
lib/axlsx/workbook/worksheet/icon_set.rb
Axlsx.IconSet.initialize_value_objects
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
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
[ "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" ]
Initalize the simple typed list of value objects I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
[ "Initalize", "the", "simple", "typed", "list", "of", "value", "objects", "I", "am", "keeping", "this", "private", "for", "now", "as", "I", "am", "not", "sure", "what", "impact", "changes", "to", "the", "required", "two", "cfvo", "objects", "will", "do", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/icon_set.rb#L75-L79
train
randym/axlsx
lib/axlsx/util/storage.rb
Axlsx.Storage.to_s
def to_s data = [@name.concat(Array.new([email protected], 0)), @name_size, @type, @color, @left, @right, @child, @created, @modified, @sector, @size].flatten data.pack(PACKING) end
ruby
def to_s data = [@name.concat(Array.new([email protected], 0)), @name_size, @type, @color, @left, @right, @child, @created, @modified, @sector, @size].flatten data.pack(PACKING) end
[ "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" ]
Creates a byte string for this storage @return [String]
[ "Creates", "a", "byte", "string", "for", "this", "storage" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/storage.rb#L20-L33
train
randym/axlsx
lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
Axlsx.FilterColumn.col_id=
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
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
[ "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" ]
Sets the col_id attribute for this filter column. @param [Integer | Cell] column_index The zero based index of the column to which this filter applies. When you specify a cell, the column index will be read off the cell @return [Integer]
[ "Sets", "the", "col_id", "attribute", "for", "this", "filter", "column", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb#L58-L62
train
randym/axlsx
lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
Axlsx.FilterColumn.apply
def apply(row, offset) row.hidden = @filter.apply(row.cells[offset+col_id.to_i]) end
ruby
def apply(row, offset) row.hidden = @filter.apply(row.cells[offset+col_id.to_i]) end
[ "def", "apply", "(", "row", ",", "offset", ")", "row", ".", "hidden", "=", "@filter", ".", "apply", "(", "row", ".", "cells", "[", "offset", "+", "col_id", ".", "to_i", "]", ")", "end" ]
Apply the filters for this column @param [Array] row A row from a worksheet that needs to be filtered.
[ "Apply", "the", "filters", "for", "this", "column" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb#L67-L69
train
randym/axlsx
lib/axlsx/workbook/worksheet/sheet_data.rb
Axlsx.SheetData.to_xml_string
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
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
[ "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" ]
Serialize the sheet data @param [String] str the string this objects serializaton will be concacted to. @return [String]
[ "Serialize", "the", "sheet", "data" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/sheet_data.rb#L18-L24
train
randym/axlsx
lib/axlsx/workbook/defined_names.rb
Axlsx.DefinedNames.to_xml_string
def to_xml_string(str = '') return if empty? str << '<definedNames>' each { |defined_name| defined_name.to_xml_string(str) } str << '</definedNames>' end
ruby
def to_xml_string(str = '') return if empty? str << '<definedNames>' each { |defined_name| defined_name.to_xml_string(str) } str << '</definedNames>' end
[ "def", "to_xml_string", "(", "str", "=", "''", ")", "return", "if", "empty?", "str", "<<", "'<definedNames>'", "each", "{", "|", "defined_name", "|", "defined_name", ".", "to_xml_string", "(", "str", ")", "}", "str", "<<", "'</definedNames>'", "end" ]
creates the DefinedNames object Serialize to xml @param [String] str @return [String]
[ "creates", "the", "DefinedNames", "object", "Serialize", "to", "xml" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/defined_names.rb#L13-L18
train
randym/axlsx
lib/axlsx/workbook/worksheet/conditional_formatting.rb
Axlsx.ConditionalFormatting.add_rule
def add_rule(rule) if rule.is_a? Axlsx::ConditionalFormattingRule @rules << rule elsif rule.is_a? Hash @rules << ConditionalFormattingRule.new(rule) end end
ruby
def add_rule(rule) if rule.is_a? Axlsx::ConditionalFormattingRule @rules << rule elsif rule.is_a? Hash @rules << ConditionalFormattingRule.new(rule) end end
[ "def", "add_rule", "(", "rule", ")", "if", "rule", ".", "is_a?", "Axlsx", "::", "ConditionalFormattingRule", "@rules", "<<", "rule", "elsif", "rule", ".", "is_a?", "Hash", "@rules", "<<", "ConditionalFormattingRule", ".", "new", "(", "rule", ")", "end", "end" ]
Add a ConditionalFormattingRule. If a hash of options is passed in create a rule on the fly. @param [ConditionalFormattingRule|Hash] rule A rule to use, or the options necessary to create one. @see ConditionalFormattingRule#initialize
[ "Add", "a", "ConditionalFormattingRule", ".", "If", "a", "hash", "of", "options", "is", "passed", "in", "create", "a", "rule", "on", "the", "fly", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/conditional_formatting.rb#L54-L60
train
randym/axlsx
lib/axlsx/workbook/worksheet/conditional_formatting.rb
Axlsx.ConditionalFormatting.to_xml_string
def to_xml_string(str = '') str << ('<conditionalFormatting sqref="' << sqref << '">') str << rules.collect{ |rule| rule.to_xml_string }.join(' ') str << '</conditionalFormatting>' end
ruby
def to_xml_string(str = '') str << ('<conditionalFormatting sqref="' << sqref << '">') str << rules.collect{ |rule| rule.to_xml_string }.join(' ') str << '</conditionalFormatting>' end
[ "def", "to_xml_string", "(", "str", "=", "''", ")", "str", "<<", "(", "'<conditionalFormatting sqref=\"'", "<<", "sqref", "<<", "'\">'", ")", "str", "<<", "rules", ".", "collect", "{", "|", "rule", "|", "rule", ".", "to_xml_string", "}", ".", "join", "(", "' '", ")", "str", "<<", "'</conditionalFormatting>'", "end" ]
Serializes the conditional formatting element @example Conditional Formatting XML looks like: <conditionalFormatting sqref="E3:E9"> <cfRule type="cellIs" dxfId="0" priority="1" operator="greaterThan"> <formula>0.5</formula> </cfRule> </conditionalFormatting> @param [String] str @return [String]
[ "Serializes", "the", "conditional", "formatting", "element" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/conditional_formatting.rb#L76-L80
train
randym/axlsx
lib/axlsx/drawing/axis.rb
Axlsx.Axis.label_rotation=
def label_rotation=(v) Axlsx::validate_int(v) adjusted = v.to_i * 60000 Axlsx::validate_angle(adjusted) @label_rotation = adjusted end
ruby
def label_rotation=(v) Axlsx::validate_int(v) adjusted = v.to_i * 60000 Axlsx::validate_angle(adjusted) @label_rotation = adjusted end
[ "def", "label_rotation", "=", "(", "v", ")", "Axlsx", "::", "validate_int", "(", "v", ")", "adjusted", "=", "v", ".", "to_i", "*", "60000", "Axlsx", "::", "validate_angle", "(", "adjusted", ")", "@label_rotation", "=", "adjusted", "end" ]
Specify the degree of label rotation to apply to labels default true
[ "Specify", "the", "degree", "of", "label", "rotation", "to", "apply", "to", "labels", "default", "true" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/axis.rb#L129-L134
train
randym/axlsx
lib/axlsx/drawing/axis.rb
Axlsx.Axis.title=
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
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
[ "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" ]
The title object for the chart. @param [String, Cell] v @return [Title]
[ "The", "title", "object", "for", "the", "chart", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/axis.rb#L139-L147
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.initialize_page_options
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
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
[ "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" ]
Initalizes page margin, setup and print options @param [Hash] options Options passed in from the initializer
[ "Initalizes", "page", "margin", "setup", "and", "print", "options" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L34-L41
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.add_conditional_formatting
def add_conditional_formatting(cells, rules) cf = ConditionalFormatting.new( :sqref => cells ) cf.add_rules rules conditional_formattings << cf conditional_formattings end
ruby
def add_conditional_formatting(cells, rules) cf = ConditionalFormatting.new( :sqref => cells ) cf.add_rules rules conditional_formattings << cf conditional_formattings end
[ "def", "add_conditional_formatting", "(", "cells", ",", "rules", ")", "cf", "=", "ConditionalFormatting", ".", "new", "(", ":sqref", "=>", "cells", ")", "cf", ".", "add_rules", "rules", "conditional_formattings", "<<", "cf", "conditional_formattings", "end" ]
Add conditional formatting to this worksheet. @param [String] cells The range to apply the formatting to @param [Array|Hash] rules An array of hashes (or just one) to create Conditional formatting rules from. @example This would format column A whenever it is FALSE. # for a longer example, see examples/example_conditional_formatting.rb (link below) worksheet.add_conditional_formatting( "A1:A1048576", { :type => :cellIs, :operator => :equal, :formula => "FALSE", :dxfId => 1, :priority => 1 } @see ConditionalFormattingRule#initialize @see file:examples/example_conditional_formatting.rb
[ "Add", "conditional", "formatting", "to", "this", "worksheet", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L419-L424
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.add_data_validation
def add_data_validation(cells, data_validation) dv = DataValidation.new(data_validation) dv.sqref = cells data_validations << dv end
ruby
def add_data_validation(cells, data_validation) dv = DataValidation.new(data_validation) dv.sqref = cells data_validations << dv end
[ "def", "add_data_validation", "(", "cells", ",", "data_validation", ")", "dv", "=", "DataValidation", ".", "new", "(", "data_validation", ")", "dv", ".", "sqref", "=", "cells", "data_validations", "<<", "dv", "end" ]
Add data validation to this worksheet. @param [String] cells The cells the validation will apply to. @param [hash] data_validation options defining the validation to apply. @see examples/data_validation.rb for an example
[ "Add", "data", "validation", "to", "this", "worksheet", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L431-L435
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.add_chart
def add_chart(chart_type, options={}) chart = worksheet_drawing.add_chart(chart_type, options) yield chart if block_given? chart end
ruby
def add_chart(chart_type, options={}) chart = worksheet_drawing.add_chart(chart_type, options) yield chart if block_given? chart end
[ "def", "add_chart", "(", "chart_type", ",", "options", "=", "{", "}", ")", "chart", "=", "worksheet_drawing", ".", "add_chart", "(", "chart_type", ",", "options", ")", "yield", "chart", "if", "block_given?", "chart", "end" ]
Adds a chart to this worksheets drawing. This is the recommended way to create charts for your worksheet. This method wraps the complexity of dealing with ooxml drawing, anchors, markers graphic frames chart objects and all the other dirty details. @param [Class] chart_type @option options [Array] start_at @option options [Array] end_at @option options [Cell, String] title @option options [Boolean] show_legend @option options [Integer] style @note each chart type also specifies additional options @see Chart @see Pie3DChart @see Bar3DChart @see Line3DChart @see README for examples
[ "Adds", "a", "chart", "to", "this", "worksheets", "drawing", ".", "This", "is", "the", "recommended", "way", "to", "create", "charts", "for", "your", "worksheet", ".", "This", "method", "wraps", "the", "complexity", "of", "dealing", "with", "ooxml", "drawing", "anchors", "markers", "graphic", "frames", "chart", "objects", "and", "all", "the", "other", "dirty", "details", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L458-L462
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.column_widths
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
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
[ "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" ]
This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go. Note that you must call column_widths AFTER adding data, otherwise the width will not be set successfully. Setting a fixed column width to nil will revert the behaviour back to calculating the width for you on the next call to add_row. @example This would set the first and third column widhts but leave the second column in autofit state. ws.column_widths 7.2, nil, 3 @note For updating only a single column it is probably easier to just set the width of the ws.column_info[col_index].width directly @param [Integer|Float|nil] widths
[ "This", "is", "a", "helper", "method", "that", "Lets", "you", "specify", "a", "fixed", "width", "for", "multiple", "columns", "in", "a", "worksheet", "in", "one", "go", ".", "Note", "that", "you", "must", "call", "column_widths", "AFTER", "adding", "data", "otherwise", "the", "width", "will", "not", "be", "set", "successfully", ".", "Setting", "a", "fixed", "column", "width", "to", "nil", "will", "revert", "the", "behaviour", "back", "to", "calculating", "the", "width", "for", "you", "on", "the", "next", "call", "to", "add_row", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L515-L521
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.col_style
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
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
[ "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" ]
Set the style for cells in a specific column @param [Integer] index the index of the column @param [Integer] style the cellXfs index @param [Hash] options @option [Integer] :row_offset only cells after this column will be updated. @note You can also specify the style for specific columns in the call to add_row by using an array for the :styles option @see Worksheet#add_row @see README.md for an example
[ "Set", "the", "style", "for", "cells", "in", "a", "specific", "column" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L531-L535
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.row_style
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
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
[ "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" ]
Set the style for cells in a specific row @param [Integer] index or range of indexes in the table @param [Integer] style the cellXfs index @param [Hash] options the options used when applying the style @option [Integer] :col_offset only cells after this column will be updated. @note You can also specify the style in the add_row call @see Worksheet#add_row @see README.md for an example
[ "Set", "the", "style", "for", "cells", "in", "a", "specific", "row" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L545-L549
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.to_sheet_node_xml_string
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
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
[ "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" ]
Returns a sheet node serialization for this sheet in the workbook.
[ "Returns", "a", "sheet", "node", "serialization", "for", "this", "sheet", "in", "the", "workbook", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L552-L558
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.to_xml_string
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
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
[ "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" ]
Serializes the worksheet object to an xml string This intentionally does not use nokogiri for performance reasons @return [String]
[ "Serializes", "the", "worksheet", "object", "to", "an", "xml", "string", "This", "intentionally", "does", "not", "use", "nokogiri", "for", "performance", "reasons" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L563-L572
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.relationships
def relationships r = Relationships.new r + [tables.relationships, worksheet_comments.relationships, hyperlinks.relationships, worksheet_drawing.relationship, pivot_tables.relationships].flatten.compact || [] r end
ruby
def relationships r = Relationships.new r + [tables.relationships, worksheet_comments.relationships, hyperlinks.relationships, worksheet_drawing.relationship, pivot_tables.relationships].flatten.compact || [] r end
[ "def", "relationships", "r", "=", "Relationships", ".", "new", "r", "+", "[", "tables", ".", "relationships", ",", "worksheet_comments", ".", "relationships", ",", "hyperlinks", ".", "relationships", ",", "worksheet_drawing", ".", "relationship", ",", "pivot_tables", ".", "relationships", "]", ".", "flatten", ".", "compact", "||", "[", "]", "r", "end" ]
The worksheet relationships. This is managed automatically by the worksheet @return [Relationships]
[ "The", "worksheet", "relationships", ".", "This", "is", "managed", "automatically", "by", "the", "worksheet" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L576-L584
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.name_to_cell
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
def name_to_cell(name) col_index, row_index = *Axlsx::name_to_indices(name) r = rows[row_index] r[col_index] if r end
[ "def", "name_to_cell", "(", "name", ")", "col_index", ",", "row_index", "=", "Axlsx", "::", "name_to_indices", "(", "name", ")", "r", "=", "rows", "[", "row_index", "]", "r", "[", "col_index", "]", "if", "r", "end" ]
returns the column and row index for a named based cell @param [String] name The cell or cell range to return. "A1" will return the first cell of the first row. @return [Cell]
[ "returns", "the", "column", "and", "row", "index", "for", "a", "named", "based", "cell" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L602-L606
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.outline_level_rows
def outline_level_rows(start_index, end_index, level = 1, collapsed = true) outline rows, (start_index..end_index), level, collapsed end
ruby
def outline_level_rows(start_index, end_index, level = 1, collapsed = true) outline rows, (start_index..end_index), level, collapsed end
[ "def", "outline_level_rows", "(", "start_index", ",", "end_index", ",", "level", "=", "1", ",", "collapsed", "=", "true", ")", "outline", "rows", ",", "(", "start_index", "..", "end_index", ")", ",", "level", ",", "collapsed", "end" ]
shortcut level to specify the outline level for a series of rows Oulining is what lets you add collapse and expand to a data set. @param [Integer] start_index The zero based index of the first row of outlining. @param [Integer] end_index The zero based index of the last row to be outlined @param [integer] level The level of outline to apply @param [Integer] collapsed The initial collapsed state of the outline group
[ "shortcut", "level", "to", "specify", "the", "outline", "level", "for", "a", "series", "of", "rows", "Oulining", "is", "what", "lets", "you", "add", "collapse", "and", "expand", "to", "a", "data", "set", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L627-L629
train
randym/axlsx
lib/axlsx/workbook/worksheet/worksheet.rb
Axlsx.Worksheet.outline_level_columns
def outline_level_columns(start_index, end_index, level = 1, collapsed = true) outline column_info, (start_index..end_index), level, collapsed end
ruby
def outline_level_columns(start_index, end_index, level = 1, collapsed = true) outline column_info, (start_index..end_index), level, collapsed end
[ "def", "outline_level_columns", "(", "start_index", ",", "end_index", ",", "level", "=", "1", ",", "collapsed", "=", "true", ")", "outline", "column_info", ",", "(", "start_index", "..", "end_index", ")", ",", "level", ",", "collapsed", "end" ]
shortcut level to specify the outline level for a series of columns Oulining is what lets you add collapse and expand to a data set. @param [Integer] start_index The zero based index of the first column of outlining. @param [Integer] end_index The zero based index of the last column to be outlined @param [integer] level The level of outline to apply @param [Integer] collapsed The initial collapsed state of the outline group
[ "shortcut", "level", "to", "specify", "the", "outline", "level", "for", "a", "series", "of", "columns", "Oulining", "is", "what", "lets", "you", "add", "collapse", "and", "expand", "to", "a", "data", "set", "." ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet.rb#L637-L639
train
randym/axlsx
lib/axlsx/workbook/worksheet/row.rb
Axlsx.Row.to_xml_string
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
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
[ "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" ]
Serializes the row @param [Integer] r_index The row index, 0 based. @param [String] str The string this rows xml will be appended to. @return [String]
[ "Serializes", "the", "row" ]
c593a08b2a929dac7aa8dc418b55e26b4c49dc34
https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/row.rb#L88-L95
train