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 |
---|---|---|---|---|---|---|---|---|---|---|---|
xero-gateway/xero_gateway | lib/xero_gateway/gateway.rb | XeroGateway.Gateway.save_manual_journal | def save_manual_journal(manual_journal)
request_xml = manual_journal.to_xml
response_xml = nil
create_or_save = nil
if manual_journal.manual_journal_id.nil?
# Create new manual journal record.
response_xml = http_put(@client, "#{@xero_url}/ManualJournals", request_xml, {})
create_or_save = :create
else
# Update existing manual journal record.
response_xml = http_post(@client, "#{@xero_url}/ManualJournals", request_xml, {})
create_or_save = :save
end
response = parse_response(response_xml, {:request_xml => request_xml}, {:request_signature => "#{create_or_save == :create ? 'PUT' : 'POST'}/ManualJournals"})
# Xero returns manual journals inside an <ManualJournals> tag, even though there's only ever
# one for this request
response.response_item = response.manual_journals.first
manual_journal.manual_journal_id = response.manual_journal.manual_journal_id if response.success? && response.manual_journal && response.manual_journal.manual_journal_id
response
end | ruby | def save_manual_journal(manual_journal)
request_xml = manual_journal.to_xml
response_xml = nil
create_or_save = nil
if manual_journal.manual_journal_id.nil?
# Create new manual journal record.
response_xml = http_put(@client, "#{@xero_url}/ManualJournals", request_xml, {})
create_or_save = :create
else
# Update existing manual journal record.
response_xml = http_post(@client, "#{@xero_url}/ManualJournals", request_xml, {})
create_or_save = :save
end
response = parse_response(response_xml, {:request_xml => request_xml}, {:request_signature => "#{create_or_save == :create ? 'PUT' : 'POST'}/ManualJournals"})
# Xero returns manual journals inside an <ManualJournals> tag, even though there's only ever
# one for this request
response.response_item = response.manual_journals.first
manual_journal.manual_journal_id = response.manual_journal.manual_journal_id if response.success? && response.manual_journal && response.manual_journal.manual_journal_id
response
end | [
"def",
"save_manual_journal",
"(",
"manual_journal",
")",
"request_xml",
"=",
"manual_journal",
".",
"to_xml",
"response_xml",
"=",
"nil",
"create_or_save",
"=",
"nil",
"if",
"manual_journal",
".",
"manual_journal_id",
".",
"nil?",
"# Create new manual journal record.",
"response_xml",
"=",
"http_put",
"(",
"@client",
",",
"\"#{@xero_url}/ManualJournals\"",
",",
"request_xml",
",",
"{",
"}",
")",
"create_or_save",
"=",
":create",
"else",
"# Update existing manual journal record.",
"response_xml",
"=",
"http_post",
"(",
"@client",
",",
"\"#{@xero_url}/ManualJournals\"",
",",
"request_xml",
",",
"{",
"}",
")",
"create_or_save",
"=",
":save",
"end",
"response",
"=",
"parse_response",
"(",
"response_xml",
",",
"{",
":request_xml",
"=>",
"request_xml",
"}",
",",
"{",
":request_signature",
"=>",
"\"#{create_or_save == :create ? 'PUT' : 'POST'}/ManualJournals\"",
"}",
")",
"# Xero returns manual journals inside an <ManualJournals> tag, even though there's only ever",
"# one for this request",
"response",
".",
"response_item",
"=",
"response",
".",
"manual_journals",
".",
"first",
"manual_journal",
".",
"manual_journal_id",
"=",
"response",
".",
"manual_journal",
".",
"manual_journal_id",
"if",
"response",
".",
"success?",
"&&",
"response",
".",
"manual_journal",
"&&",
"response",
".",
"manual_journal",
".",
"manual_journal_id",
"response",
"end"
] | Create or update a manual journal record based on if it has an manual_journal_id. | [
"Create",
"or",
"update",
"a",
"manual",
"journal",
"record",
"based",
"on",
"if",
"it",
"has",
"an",
"manual_journal_id",
"."
] | 6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5 | https://github.com/xero-gateway/xero_gateway/blob/6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5/lib/xero_gateway/gateway.rb#L735-L759 | train |
xero-gateway/xero_gateway | lib/xero_gateway/credit_note.rb | XeroGateway.CreditNote.build_contact | def build_contact(params = {})
self.contact = gateway ? gateway.build_contact(params) : Contact.new(params)
end | ruby | def build_contact(params = {})
self.contact = gateway ? gateway.build_contact(params) : Contact.new(params)
end | [
"def",
"build_contact",
"(",
"params",
"=",
"{",
"}",
")",
"self",
".",
"contact",
"=",
"gateway",
"?",
"gateway",
".",
"build_contact",
"(",
"params",
")",
":",
"Contact",
".",
"new",
"(",
"params",
")",
"end"
] | Helper method to create the associated contact object. | [
"Helper",
"method",
"to",
"create",
"the",
"associated",
"contact",
"object",
"."
] | 6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5 | https://github.com/xero-gateway/xero_gateway/blob/6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5/lib/xero_gateway/credit_note.rb#L99-L101 | train |
xero-gateway/xero_gateway | lib/xero_gateway/oauth.rb | XeroGateway.OAuth.renew_access_token | def renew_access_token(access_token = nil, access_secret = nil, session_handle = nil)
access_token ||= @atoken
access_secret ||= @asecret
session_handle ||= @session_handle
old_token = ::OAuth::RequestToken.new(consumer, access_token, access_secret)
# Underlying oauth consumer accepts body params and headers for request via positional params - explicit nilling of
# body parameters allows for correct position for headers
access_token = old_token.get_access_token({
:oauth_session_handle => session_handle,
:token => old_token
}, nil, @base_headers)
update_attributes_from_token(access_token)
rescue ::OAuth::Unauthorized => e
# If the original access token is for some reason invalid an OAuth::Unauthorized could be raised.
# In this case raise a XeroGateway::OAuth::TokenInvalid which can be captured by the caller. In this
# situation the end user will need to re-authorize the application via the request token authorization URL
raise XeroGateway::OAuth::TokenInvalid.new(e.message)
end | ruby | def renew_access_token(access_token = nil, access_secret = nil, session_handle = nil)
access_token ||= @atoken
access_secret ||= @asecret
session_handle ||= @session_handle
old_token = ::OAuth::RequestToken.new(consumer, access_token, access_secret)
# Underlying oauth consumer accepts body params and headers for request via positional params - explicit nilling of
# body parameters allows for correct position for headers
access_token = old_token.get_access_token({
:oauth_session_handle => session_handle,
:token => old_token
}, nil, @base_headers)
update_attributes_from_token(access_token)
rescue ::OAuth::Unauthorized => e
# If the original access token is for some reason invalid an OAuth::Unauthorized could be raised.
# In this case raise a XeroGateway::OAuth::TokenInvalid which can be captured by the caller. In this
# situation the end user will need to re-authorize the application via the request token authorization URL
raise XeroGateway::OAuth::TokenInvalid.new(e.message)
end | [
"def",
"renew_access_token",
"(",
"access_token",
"=",
"nil",
",",
"access_secret",
"=",
"nil",
",",
"session_handle",
"=",
"nil",
")",
"access_token",
"||=",
"@atoken",
"access_secret",
"||=",
"@asecret",
"session_handle",
"||=",
"@session_handle",
"old_token",
"=",
"::",
"OAuth",
"::",
"RequestToken",
".",
"new",
"(",
"consumer",
",",
"access_token",
",",
"access_secret",
")",
"# Underlying oauth consumer accepts body params and headers for request via positional params - explicit nilling of ",
"# body parameters allows for correct position for headers",
"access_token",
"=",
"old_token",
".",
"get_access_token",
"(",
"{",
":oauth_session_handle",
"=>",
"session_handle",
",",
":token",
"=>",
"old_token",
"}",
",",
"nil",
",",
"@base_headers",
")",
"update_attributes_from_token",
"(",
"access_token",
")",
"rescue",
"::",
"OAuth",
"::",
"Unauthorized",
"=>",
"e",
"# If the original access token is for some reason invalid an OAuth::Unauthorized could be raised.",
"# In this case raise a XeroGateway::OAuth::TokenInvalid which can be captured by the caller. In this",
"# situation the end user will need to re-authorize the application via the request token authorization URL",
"raise",
"XeroGateway",
"::",
"OAuth",
"::",
"TokenInvalid",
".",
"new",
"(",
"e",
".",
"message",
")",
"end"
] | Renewing access tokens only works for Partner applications | [
"Renewing",
"access",
"tokens",
"only",
"works",
"for",
"Partner",
"applications"
] | 6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5 | https://github.com/xero-gateway/xero_gateway/blob/6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5/lib/xero_gateway/oauth.rb#L67-L87 | train |
xero-gateway/xero_gateway | lib/xero_gateway/oauth.rb | XeroGateway.OAuth.update_attributes_from_token | def update_attributes_from_token(access_token)
@expires_at = Time.now + access_token.params[:oauth_expires_in].to_i
@authorization_expires_at = Time.now + access_token.params[:oauth_authorization_expires_in].to_i
@session_handle = access_token.params[:oauth_session_handle]
@atoken, @asecret = access_token.token, access_token.secret
@access_token = nil
end | ruby | def update_attributes_from_token(access_token)
@expires_at = Time.now + access_token.params[:oauth_expires_in].to_i
@authorization_expires_at = Time.now + access_token.params[:oauth_authorization_expires_in].to_i
@session_handle = access_token.params[:oauth_session_handle]
@atoken, @asecret = access_token.token, access_token.secret
@access_token = nil
end | [
"def",
"update_attributes_from_token",
"(",
"access_token",
")",
"@expires_at",
"=",
"Time",
".",
"now",
"+",
"access_token",
".",
"params",
"[",
":oauth_expires_in",
"]",
".",
"to_i",
"@authorization_expires_at",
"=",
"Time",
".",
"now",
"+",
"access_token",
".",
"params",
"[",
":oauth_authorization_expires_in",
"]",
".",
"to_i",
"@session_handle",
"=",
"access_token",
".",
"params",
"[",
":oauth_session_handle",
"]",
"@atoken",
",",
"@asecret",
"=",
"access_token",
".",
"token",
",",
"access_token",
".",
"secret",
"@access_token",
"=",
"nil",
"end"
] | Update instance variables with those from the AccessToken. | [
"Update",
"instance",
"variables",
"with",
"those",
"from",
"the",
"AccessToken",
"."
] | 6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5 | https://github.com/xero-gateway/xero_gateway/blob/6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5/lib/xero_gateway/oauth.rb#L108-L114 | train |
xero-gateway/xero_gateway | lib/xero_gateway/bank_transaction.rb | XeroGateway.BankTransaction.valid? | def valid?
@errors = []
if !bank_transaction_id.nil? && bank_transaction_id !~ GUID_REGEX
@errors << ['bank_transaction_id', 'must be blank or a valid Xero GUID']
end
if type && !TYPES[type]
@errors << ['type', "must be one of #{TYPES.keys.join('/')}"]
end
if status && !STATUSES[status]
@errors << ['status', "must be one of #{STATUSES.keys.join('/')}"]
end
unless date
@errors << ['date', "can't be blank"]
end
# Make sure contact is valid.
unless @contact && @contact.valid?
@errors << ['contact', 'is invalid']
end
# Make sure all line_items are valid.
unless line_items.all? { | line_item | line_item.valid? }
@errors << ['line_items', "at least one line item invalid"]
end
@errors.size == 0
end | ruby | def valid?
@errors = []
if !bank_transaction_id.nil? && bank_transaction_id !~ GUID_REGEX
@errors << ['bank_transaction_id', 'must be blank or a valid Xero GUID']
end
if type && !TYPES[type]
@errors << ['type', "must be one of #{TYPES.keys.join('/')}"]
end
if status && !STATUSES[status]
@errors << ['status', "must be one of #{STATUSES.keys.join('/')}"]
end
unless date
@errors << ['date', "can't be blank"]
end
# Make sure contact is valid.
unless @contact && @contact.valid?
@errors << ['contact', 'is invalid']
end
# Make sure all line_items are valid.
unless line_items.all? { | line_item | line_item.valid? }
@errors << ['line_items', "at least one line item invalid"]
end
@errors.size == 0
end | [
"def",
"valid?",
"@errors",
"=",
"[",
"]",
"if",
"!",
"bank_transaction_id",
".",
"nil?",
"&&",
"bank_transaction_id",
"!~",
"GUID_REGEX",
"@errors",
"<<",
"[",
"'bank_transaction_id'",
",",
"'must be blank or a valid Xero GUID'",
"]",
"end",
"if",
"type",
"&&",
"!",
"TYPES",
"[",
"type",
"]",
"@errors",
"<<",
"[",
"'type'",
",",
"\"must be one of #{TYPES.keys.join('/')}\"",
"]",
"end",
"if",
"status",
"&&",
"!",
"STATUSES",
"[",
"status",
"]",
"@errors",
"<<",
"[",
"'status'",
",",
"\"must be one of #{STATUSES.keys.join('/')}\"",
"]",
"end",
"unless",
"date",
"@errors",
"<<",
"[",
"'date'",
",",
"\"can't be blank\"",
"]",
"end",
"# Make sure contact is valid.",
"unless",
"@contact",
"&&",
"@contact",
".",
"valid?",
"@errors",
"<<",
"[",
"'contact'",
",",
"'is invalid'",
"]",
"end",
"# Make sure all line_items are valid.",
"unless",
"line_items",
".",
"all?",
"{",
"|",
"line_item",
"|",
"line_item",
".",
"valid?",
"}",
"@errors",
"<<",
"[",
"'line_items'",
",",
"\"at least one line item invalid\"",
"]",
"end",
"@errors",
".",
"size",
"==",
"0",
"end"
] | Validate the BankTransaction record according to what will be valid by the gateway.
Usage:
bank_transaction.valid? # Returns true/false
Additionally sets bank_transaction.errors array to an array of field/error. | [
"Validate",
"the",
"BankTransaction",
"record",
"according",
"to",
"what",
"will",
"be",
"valid",
"by",
"the",
"gateway",
"."
] | 6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5 | https://github.com/xero-gateway/xero_gateway/blob/6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5/lib/xero_gateway/bank_transaction.rb#L65-L95 | train |
xero-gateway/xero_gateway | lib/xero_gateway/manual_journal.rb | XeroGateway.ManualJournal.valid? | def valid?
@errors = []
if !manual_journal_id.nil? && manual_journal_id !~ GUID_REGEX
@errors << ['manual_journal_id', 'must be blank or a valid Xero GUID']
end
if narration.blank?
@errors << ['narration', "can't be blank"]
end
unless date
@errors << ['date', "can't be blank"]
end
# Make sure all journal_items are valid.
unless journal_lines.all? { | journal_line | journal_line.valid? }
@errors << ['journal_lines', "at least one journal line invalid"]
end
# make sure there are at least 2 journal lines
unless journal_lines.length > 1
@errors << ['journal_lines', "journal must contain at least two individual journal lines"]
end
if journal_lines.length > 100
@errors << ['journal_lines', "journal must contain less than one hundred journal lines"]
end
unless journal_lines.sum(&:line_amount).to_f == 0.0
@errors << ['journal_lines', "the total debits must be equal to total credits"]
end
@errors.size == 0
end | ruby | def valid?
@errors = []
if !manual_journal_id.nil? && manual_journal_id !~ GUID_REGEX
@errors << ['manual_journal_id', 'must be blank or a valid Xero GUID']
end
if narration.blank?
@errors << ['narration', "can't be blank"]
end
unless date
@errors << ['date', "can't be blank"]
end
# Make sure all journal_items are valid.
unless journal_lines.all? { | journal_line | journal_line.valid? }
@errors << ['journal_lines', "at least one journal line invalid"]
end
# make sure there are at least 2 journal lines
unless journal_lines.length > 1
@errors << ['journal_lines', "journal must contain at least two individual journal lines"]
end
if journal_lines.length > 100
@errors << ['journal_lines', "journal must contain less than one hundred journal lines"]
end
unless journal_lines.sum(&:line_amount).to_f == 0.0
@errors << ['journal_lines', "the total debits must be equal to total credits"]
end
@errors.size == 0
end | [
"def",
"valid?",
"@errors",
"=",
"[",
"]",
"if",
"!",
"manual_journal_id",
".",
"nil?",
"&&",
"manual_journal_id",
"!~",
"GUID_REGEX",
"@errors",
"<<",
"[",
"'manual_journal_id'",
",",
"'must be blank or a valid Xero GUID'",
"]",
"end",
"if",
"narration",
".",
"blank?",
"@errors",
"<<",
"[",
"'narration'",
",",
"\"can't be blank\"",
"]",
"end",
"unless",
"date",
"@errors",
"<<",
"[",
"'date'",
",",
"\"can't be blank\"",
"]",
"end",
"# Make sure all journal_items are valid.",
"unless",
"journal_lines",
".",
"all?",
"{",
"|",
"journal_line",
"|",
"journal_line",
".",
"valid?",
"}",
"@errors",
"<<",
"[",
"'journal_lines'",
",",
"\"at least one journal line invalid\"",
"]",
"end",
"# make sure there are at least 2 journal lines",
"unless",
"journal_lines",
".",
"length",
">",
"1",
"@errors",
"<<",
"[",
"'journal_lines'",
",",
"\"journal must contain at least two individual journal lines\"",
"]",
"end",
"if",
"journal_lines",
".",
"length",
">",
"100",
"@errors",
"<<",
"[",
"'journal_lines'",
",",
"\"journal must contain less than one hundred journal lines\"",
"]",
"end",
"unless",
"journal_lines",
".",
"sum",
"(",
":line_amount",
")",
".",
"to_f",
"==",
"0.0",
"@errors",
"<<",
"[",
"'journal_lines'",
",",
"\"the total debits must be equal to total credits\"",
"]",
"end",
"@errors",
".",
"size",
"==",
"0",
"end"
] | Validate the ManualJournal record according to what will be valid by the gateway.
Usage:
manual_journal.valid? # Returns true/false
Additionally sets manual_journal.errors array to an array of field/error. | [
"Validate",
"the",
"ManualJournal",
"record",
"according",
"to",
"what",
"will",
"be",
"valid",
"by",
"the",
"gateway",
"."
] | 6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5 | https://github.com/xero-gateway/xero_gateway/blob/6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5/lib/xero_gateway/manual_journal.rb#L61-L95 | train |
xero-gateway/xero_gateway | lib/xero_gateway/tracking_category.rb | XeroGateway.TrackingCategory.to_xml_for_invoice_messages | def to_xml_for_invoice_messages(b = Builder::XmlMarkup.new)
b.TrackingCategory {
b.TrackingCategoryID self.tracking_category_id unless tracking_category_id.nil?
b.Name self.name
b.Option self.options.is_a?(Array) ? self.options.first : self.options.to_s
}
end | ruby | def to_xml_for_invoice_messages(b = Builder::XmlMarkup.new)
b.TrackingCategory {
b.TrackingCategoryID self.tracking_category_id unless tracking_category_id.nil?
b.Name self.name
b.Option self.options.is_a?(Array) ? self.options.first : self.options.to_s
}
end | [
"def",
"to_xml_for_invoice_messages",
"(",
"b",
"=",
"Builder",
"::",
"XmlMarkup",
".",
"new",
")",
"b",
".",
"TrackingCategory",
"{",
"b",
".",
"TrackingCategoryID",
"self",
".",
"tracking_category_id",
"unless",
"tracking_category_id",
".",
"nil?",
"b",
".",
"Name",
"self",
".",
"name",
"b",
".",
"Option",
"self",
".",
"options",
".",
"is_a?",
"(",
"Array",
")",
"?",
"self",
".",
"options",
".",
"first",
":",
"self",
".",
"options",
".",
"to_s",
"}",
"end"
] | When a tracking category is serialized as part of an invoice it may only have a single
option, and the Options tag is omitted | [
"When",
"a",
"tracking",
"category",
"is",
"serialized",
"as",
"part",
"of",
"an",
"invoice",
"it",
"may",
"only",
"have",
"a",
"single",
"option",
"and",
"the",
"Options",
"tag",
"is",
"omitted"
] | 6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5 | https://github.com/xero-gateway/xero_gateway/blob/6f0afbc3ebb756b66c7eff6c37f77f1e33bd07c5/lib/xero_gateway/tracking_category.rb#L80-L86 | train |
winston/google_visualr | lib/google_visualr/base_chart.rb | GoogleVisualr.BaseChart.to_js | def to_js(element_id)
js = ""
js << "\n<script type='text/javascript'>"
js << load_js(element_id)
js << draw_js(element_id)
js << "\n</script>"
js
end | ruby | def to_js(element_id)
js = ""
js << "\n<script type='text/javascript'>"
js << load_js(element_id)
js << draw_js(element_id)
js << "\n</script>"
js
end | [
"def",
"to_js",
"(",
"element_id",
")",
"js",
"=",
"\"\"",
"js",
"<<",
"\"\\n<script type='text/javascript'>\"",
"js",
"<<",
"load_js",
"(",
"element_id",
")",
"js",
"<<",
"draw_js",
"(",
"element_id",
")",
"js",
"<<",
"\"\\n</script>\"",
"js",
"end"
] | Generates JavaScript and renders the Google Chart in the final HTML output.
Parameters:
*div_id [Required] The ID of the DIV element that the Google Chart should be rendered in. | [
"Generates",
"JavaScript",
"and",
"renders",
"the",
"Google",
"Chart",
"in",
"the",
"final",
"HTML",
"output",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/base_chart.rb#L63-L70 | train |
winston/google_visualr | lib/google_visualr/base_chart.rb | GoogleVisualr.BaseChart.draw_js | def draw_js(element_id)
js = ""
js << "\n function #{chart_function_name(element_id)}() {"
js << "\n #{@data_table.to_js}"
js << "\n var chart = new google.#{chart_class}.#{chart_name}(document.getElementById('#{element_id}'));"
@listeners.each do |listener|
js << "\n google.visualization.events.addListener(chart, '#{listener[:event]}', #{listener[:callback]});"
end
js << "\n chart.draw(data_table, #{js_parameters(@options)});"
js << "\n };"
js
end | ruby | def draw_js(element_id)
js = ""
js << "\n function #{chart_function_name(element_id)}() {"
js << "\n #{@data_table.to_js}"
js << "\n var chart = new google.#{chart_class}.#{chart_name}(document.getElementById('#{element_id}'));"
@listeners.each do |listener|
js << "\n google.visualization.events.addListener(chart, '#{listener[:event]}', #{listener[:callback]});"
end
js << "\n chart.draw(data_table, #{js_parameters(@options)});"
js << "\n };"
js
end | [
"def",
"draw_js",
"(",
"element_id",
")",
"js",
"=",
"\"\"",
"js",
"<<",
"\"\\n function #{chart_function_name(element_id)}() {\"",
"js",
"<<",
"\"\\n #{@data_table.to_js}\"",
"js",
"<<",
"\"\\n var chart = new google.#{chart_class}.#{chart_name}(document.getElementById('#{element_id}'));\"",
"@listeners",
".",
"each",
"do",
"|",
"listener",
"|",
"js",
"<<",
"\"\\n google.visualization.events.addListener(chart, '#{listener[:event]}', #{listener[:callback]});\"",
"end",
"js",
"<<",
"\"\\n chart.draw(data_table, #{js_parameters(@options)});\"",
"js",
"<<",
"\"\\n };\"",
"js",
"end"
] | Generates JavaScript function for rendering the chart.
Parameters:
*div_id [Required] The ID of the DIV element that the Google Chart should be rendered in. | [
"Generates",
"JavaScript",
"function",
"for",
"rendering",
"the",
"chart",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/base_chart.rb#L86-L97 | train |
winston/google_visualr | lib/google_visualr/data_table.rb | GoogleVisualr.DataTable.new_columns | def new_columns(columns)
columns.each do |column|
new_column(column[:type], column[:label], column[:id], column[:role], column[:pattern])
end
end | ruby | def new_columns(columns)
columns.each do |column|
new_column(column[:type], column[:label], column[:id], column[:role], column[:pattern])
end
end | [
"def",
"new_columns",
"(",
"columns",
")",
"columns",
".",
"each",
"do",
"|",
"column",
"|",
"new_column",
"(",
"column",
"[",
":type",
"]",
",",
"column",
"[",
":label",
"]",
",",
"column",
"[",
":id",
"]",
",",
"column",
"[",
":role",
"]",
",",
"column",
"[",
":pattern",
"]",
")",
"end",
"end"
] | Adds multiple columns to the data_table.
Parameters:
* columns [Required] An array of column objects {:type, :label, :id, :role, :pattern}. Calls new_column for each column object. | [
"Adds",
"multiple",
"columns",
"to",
"the",
"data_table",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/data_table.rb#L90-L94 | train |
winston/google_visualr | lib/google_visualr/data_table.rb | GoogleVisualr.DataTable.set_column | def set_column(column_index, column_values)
if @rows.size < column_values.size
1.upto(column_values.size - @rows.size) { @rows << Array.new }
end
column_values.each_with_index do |column_value, row_index|
set_cell(row_index, column_index, column_value)
end
end | ruby | def set_column(column_index, column_values)
if @rows.size < column_values.size
1.upto(column_values.size - @rows.size) { @rows << Array.new }
end
column_values.each_with_index do |column_value, row_index|
set_cell(row_index, column_index, column_value)
end
end | [
"def",
"set_column",
"(",
"column_index",
",",
"column_values",
")",
"if",
"@rows",
".",
"size",
"<",
"column_values",
".",
"size",
"1",
".",
"upto",
"(",
"column_values",
".",
"size",
"-",
"@rows",
".",
"size",
")",
"{",
"@rows",
"<<",
"Array",
".",
"new",
"}",
"end",
"column_values",
".",
"each_with_index",
"do",
"|",
"column_value",
",",
"row_index",
"|",
"set_cell",
"(",
"row_index",
",",
"column_index",
",",
"column_value",
")",
"end",
"end"
] | Sets a column in data_table, specified by column_index with an array of column_values. column_index starts from 0.
Parameters
* column_index [Required] The column to assign column_values. column_index starts from 0.
* column_values [Required] An array of cell values. | [
"Sets",
"a",
"column",
"in",
"data_table",
"specified",
"by",
"column_index",
"with",
"an",
"array",
"of",
"column_values",
".",
"column_index",
"starts",
"from",
"0",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/data_table.rb#L101-L109 | train |
winston/google_visualr | lib/google_visualr/data_table.rb | GoogleVisualr.DataTable.add_row | def add_row(row_values=[])
@rows << Array.new
row_index = @rows.size-1
row_values.each_with_index do |row_value, column_index|
set_cell(row_index, column_index, row_value)
end
end | ruby | def add_row(row_values=[])
@rows << Array.new
row_index = @rows.size-1
row_values.each_with_index do |row_value, column_index|
set_cell(row_index, column_index, row_value)
end
end | [
"def",
"add_row",
"(",
"row_values",
"=",
"[",
"]",
")",
"@rows",
"<<",
"Array",
".",
"new",
"row_index",
"=",
"@rows",
".",
"size",
"-",
"1",
"row_values",
".",
"each_with_index",
"do",
"|",
"row_value",
",",
"column_index",
"|",
"set_cell",
"(",
"row_index",
",",
"column_index",
",",
"row_value",
")",
"end",
"end"
] | Adds a new row to the data_table.
Call method without any parameters to add an empty row, otherwise, call method with a row object.
Parameters:
* row [Optional] An array of cell values specifying the data for the new row.
- You can specify a value for a cell (e.g. 'hi') or specify a formatted value using cell objects (e.g. {v:55, f:'Fifty-five'}) as described in the constructor section.
- You can mix simple values and cell objects in the same method call.
- To create an empty cell, use nil or empty string. | [
"Adds",
"a",
"new",
"row",
"to",
"the",
"data_table",
".",
"Call",
"method",
"without",
"any",
"parameters",
"to",
"add",
"an",
"empty",
"row",
"otherwise",
"call",
"method",
"with",
"a",
"row",
"object",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/data_table.rb#L127-L134 | train |
winston/google_visualr | lib/google_visualr/data_table.rb | GoogleVisualr.DataTable.add_rows | def add_rows(array_or_num)
if array_or_num.is_a?(Array)
array_or_num.each do |row|
add_row(row)
end
else
array_or_num.times do
add_row
end
end
end | ruby | def add_rows(array_or_num)
if array_or_num.is_a?(Array)
array_or_num.each do |row|
add_row(row)
end
else
array_or_num.times do
add_row
end
end
end | [
"def",
"add_rows",
"(",
"array_or_num",
")",
"if",
"array_or_num",
".",
"is_a?",
"(",
"Array",
")",
"array_or_num",
".",
"each",
"do",
"|",
"row",
"|",
"add_row",
"(",
"row",
")",
"end",
"else",
"array_or_num",
".",
"times",
"do",
"add_row",
"end",
"end",
"end"
] | Adds multiple rows to the data_table. You can call this method with data to populate a set of new rows or create new empty rows.
Parameters:
* array_or_num [Required] Either an array or a number.
- Array: An array of row objects used to populate a set of new rows. Each row is an object as described in add_row().
- Number: A number specifying the number of new empty rows to create. | [
"Adds",
"multiple",
"rows",
"to",
"the",
"data_table",
".",
"You",
"can",
"call",
"this",
"method",
"with",
"data",
"to",
"populate",
"a",
"set",
"of",
"new",
"rows",
"or",
"create",
"new",
"empty",
"rows",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/data_table.rb#L142-L152 | train |
winston/google_visualr | lib/google_visualr/data_table.rb | GoogleVisualr.DataTable.get_cell | def get_cell(row_index, column_index)
if within_range?(row_index, column_index)
@rows[row_index][column_index].v
else
raise RangeError, "row_index and column_index MUST be < @rows.size and @cols.size", caller
end
end | ruby | def get_cell(row_index, column_index)
if within_range?(row_index, column_index)
@rows[row_index][column_index].v
else
raise RangeError, "row_index and column_index MUST be < @rows.size and @cols.size", caller
end
end | [
"def",
"get_cell",
"(",
"row_index",
",",
"column_index",
")",
"if",
"within_range?",
"(",
"row_index",
",",
"column_index",
")",
"@rows",
"[",
"row_index",
"]",
"[",
"column_index",
"]",
".",
"v",
"else",
"raise",
"RangeError",
",",
"\"row_index and column_index MUST be < @rows.size and @cols.size\"",
",",
"caller",
"end",
"end"
] | Gets a cell value from the visualization, at row_index, column_index. row_index and column_index start from 0.
Parameters:
* row_index [Required] row_index starts from 0.
* column_index [Required] column_index starts from 0. | [
"Gets",
"a",
"cell",
"value",
"from",
"the",
"visualization",
"at",
"row_index",
"column_index",
".",
"row_index",
"and",
"column_index",
"start",
"from",
"0",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/data_table.rb#L185-L191 | train |
winston/google_visualr | lib/google_visualr/data_table.rb | GoogleVisualr.DataTable.to_js | def to_js
js = "var data_table = new google.visualization.DataTable();"
@cols.each do |column|
js << "data_table.addColumn("
js << display(column)
js << ");"
end
@rows.each do |row|
js << "data_table.addRow("
js << "[#{row.map(&:to_js).join(", ")}]" unless row.empty?
js << ");"
end
if @formatters
@formatters.each do |formatter|
js << formatter.to_js
end
end
js
end | ruby | def to_js
js = "var data_table = new google.visualization.DataTable();"
@cols.each do |column|
js << "data_table.addColumn("
js << display(column)
js << ");"
end
@rows.each do |row|
js << "data_table.addRow("
js << "[#{row.map(&:to_js).join(", ")}]" unless row.empty?
js << ");"
end
if @formatters
@formatters.each do |formatter|
js << formatter.to_js
end
end
js
end | [
"def",
"to_js",
"js",
"=",
"\"var data_table = new google.visualization.DataTable();\"",
"@cols",
".",
"each",
"do",
"|",
"column",
"|",
"js",
"<<",
"\"data_table.addColumn(\"",
"js",
"<<",
"display",
"(",
"column",
")",
"js",
"<<",
"\");\"",
"end",
"@rows",
".",
"each",
"do",
"|",
"row",
"|",
"js",
"<<",
"\"data_table.addRow(\"",
"js",
"<<",
"\"[#{row.map(&:to_js).join(\", \")}]\"",
"unless",
"row",
".",
"empty?",
"js",
"<<",
"\");\"",
"end",
"if",
"@formatters",
"@formatters",
".",
"each",
"do",
"|",
"formatter",
"|",
"js",
"<<",
"formatter",
".",
"to_js",
"end",
"end",
"js",
"end"
] | Returns the JavaScript equivalent for this data_table instance. | [
"Returns",
"the",
"JavaScript",
"equivalent",
"for",
"this",
"data_table",
"instance",
"."
] | 17b97114a345baadd011e7b442b9a6c91a2b7ab5 | https://github.com/winston/google_visualr/blob/17b97114a345baadd011e7b442b9a6c91a2b7ab5/lib/google_visualr/data_table.rb#L203-L225 | train |
sparkleformation/sfn | lib/sfn/callback.rb | Sfn.Callback.run_action | def run_action(msg)
ui.info("#{msg}... ", :nonewline)
begin
result = yield
ui.puts ui.color("complete!", :green, :bold)
result
rescue => e
ui.puts ui.color("error!", :red, :bold)
ui.error "Reason - #{e}"
raise
end
end | ruby | def run_action(msg)
ui.info("#{msg}... ", :nonewline)
begin
result = yield
ui.puts ui.color("complete!", :green, :bold)
result
rescue => e
ui.puts ui.color("error!", :red, :bold)
ui.error "Reason - #{e}"
raise
end
end | [
"def",
"run_action",
"(",
"msg",
")",
"ui",
".",
"info",
"(",
"\"#{msg}... \"",
",",
":nonewline",
")",
"begin",
"result",
"=",
"yield",
"ui",
".",
"puts",
"ui",
".",
"color",
"(",
"\"complete!\"",
",",
":green",
",",
":bold",
")",
"result",
"rescue",
"=>",
"e",
"ui",
".",
"puts",
"ui",
".",
"color",
"(",
"\"error!\"",
",",
":red",
",",
":bold",
")",
"ui",
".",
"error",
"\"Reason - #{e}\"",
"raise",
"end",
"end"
] | Create a new callback instance
@param ui [Bogo::Ui]
@param config [Smash] configuration hash
@param arguments [Array<String>] arguments from the CLI
@param api [Provider] API connection
@return [self]
Wrap action within status text
@param msg [String] action text
@yieldblock action to perform
@return [Object] result of yield | [
"Create",
"a",
"new",
"callback",
"instance"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/callback.rb#L39-L50 | train |
sparkleformation/sfn | lib/sfn/provider.rb | Sfn.Provider.save_expanded_stack | def save_expanded_stack(stack_id, stack_attributes)
current_stacks = MultiJson.load(cached_stacks)
cache.locked_action(:stacks_lock) do
logger.info "Saving expanded stack attributes in cache (#{stack_id})"
current_stacks[stack_id] = stack_attributes.merge("Cached" => Time.now.to_i)
cache[:stacks].value = MultiJson.dump(current_stacks)
end
true
end | ruby | def save_expanded_stack(stack_id, stack_attributes)
current_stacks = MultiJson.load(cached_stacks)
cache.locked_action(:stacks_lock) do
logger.info "Saving expanded stack attributes in cache (#{stack_id})"
current_stacks[stack_id] = stack_attributes.merge("Cached" => Time.now.to_i)
cache[:stacks].value = MultiJson.dump(current_stacks)
end
true
end | [
"def",
"save_expanded_stack",
"(",
"stack_id",
",",
"stack_attributes",
")",
"current_stacks",
"=",
"MultiJson",
".",
"load",
"(",
"cached_stacks",
")",
"cache",
".",
"locked_action",
"(",
":stacks_lock",
")",
"do",
"logger",
".",
"info",
"\"Saving expanded stack attributes in cache (#{stack_id})\"",
"current_stacks",
"[",
"stack_id",
"]",
"=",
"stack_attributes",
".",
"merge",
"(",
"\"Cached\"",
"=>",
"Time",
".",
"now",
".",
"to_i",
")",
"cache",
"[",
":stacks",
"]",
".",
"value",
"=",
"MultiJson",
".",
"dump",
"(",
"current_stacks",
")",
"end",
"true",
"end"
] | Store stack attribute changes
@param stack_id [String]
@param stack_attributes [Hash]
@return [TrueClass] | [
"Store",
"stack",
"attribute",
"changes"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/provider.rb#L125-L133 | train |
sparkleformation/sfn | lib/sfn/provider.rb | Sfn.Provider.remove_stack | def remove_stack(stack_id)
current_stacks = MultiJson.load(cached_stacks)
logger.info "Attempting to remove stack from internal cache (#{stack_id})"
cache.locked_action(:stacks_lock) do
val = current_stacks.delete(stack_id)
logger.info "Successfully removed stack from internal cache (#{stack_id})"
cache[:stacks].value = MultiJson.dump(current_stacks)
!!val
end
end | ruby | def remove_stack(stack_id)
current_stacks = MultiJson.load(cached_stacks)
logger.info "Attempting to remove stack from internal cache (#{stack_id})"
cache.locked_action(:stacks_lock) do
val = current_stacks.delete(stack_id)
logger.info "Successfully removed stack from internal cache (#{stack_id})"
cache[:stacks].value = MultiJson.dump(current_stacks)
!!val
end
end | [
"def",
"remove_stack",
"(",
"stack_id",
")",
"current_stacks",
"=",
"MultiJson",
".",
"load",
"(",
"cached_stacks",
")",
"logger",
".",
"info",
"\"Attempting to remove stack from internal cache (#{stack_id})\"",
"cache",
".",
"locked_action",
"(",
":stacks_lock",
")",
"do",
"val",
"=",
"current_stacks",
".",
"delete",
"(",
"stack_id",
")",
"logger",
".",
"info",
"\"Successfully removed stack from internal cache (#{stack_id})\"",
"cache",
"[",
":stacks",
"]",
".",
"value",
"=",
"MultiJson",
".",
"dump",
"(",
"current_stacks",
")",
"!",
"!",
"val",
"end",
"end"
] | Remove stack from the cache
@param stack_id [String]
@return [TrueClass, FalseClass] | [
"Remove",
"stack",
"from",
"the",
"cache"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/provider.rb#L139-L148 | train |
sparkleformation/sfn | lib/sfn/provider.rb | Sfn.Provider.expand_stack | def expand_stack(stack)
logger.info "Stack expansion requested (#{stack.id})"
if ((stack.in_progress? && Time.now.to_i - stack.attributes["Cached"].to_i > stack_expansion_interval) ||
!stack.attributes["Cached"])
begin
expanded = false
cache.locked_action(:stack_expansion_lock) do
expanded = true
stack.reload
stack.data["Cached"] = Time.now.to_i
end
if expanded
save_expanded_stack(stack.id, stack.to_json)
end
rescue => e
logger.error "Stack expansion failed (#{stack.id}) - #{e.class}: #{e}"
end
else
logger.info "Stack has been cached within expand interval. Expansion prevented. (#{stack.id})"
end
end | ruby | def expand_stack(stack)
logger.info "Stack expansion requested (#{stack.id})"
if ((stack.in_progress? && Time.now.to_i - stack.attributes["Cached"].to_i > stack_expansion_interval) ||
!stack.attributes["Cached"])
begin
expanded = false
cache.locked_action(:stack_expansion_lock) do
expanded = true
stack.reload
stack.data["Cached"] = Time.now.to_i
end
if expanded
save_expanded_stack(stack.id, stack.to_json)
end
rescue => e
logger.error "Stack expansion failed (#{stack.id}) - #{e.class}: #{e}"
end
else
logger.info "Stack has been cached within expand interval. Expansion prevented. (#{stack.id})"
end
end | [
"def",
"expand_stack",
"(",
"stack",
")",
"logger",
".",
"info",
"\"Stack expansion requested (#{stack.id})\"",
"if",
"(",
"(",
"stack",
".",
"in_progress?",
"&&",
"Time",
".",
"now",
".",
"to_i",
"-",
"stack",
".",
"attributes",
"[",
"\"Cached\"",
"]",
".",
"to_i",
">",
"stack_expansion_interval",
")",
"||",
"!",
"stack",
".",
"attributes",
"[",
"\"Cached\"",
"]",
")",
"begin",
"expanded",
"=",
"false",
"cache",
".",
"locked_action",
"(",
":stack_expansion_lock",
")",
"do",
"expanded",
"=",
"true",
"stack",
".",
"reload",
"stack",
".",
"data",
"[",
"\"Cached\"",
"]",
"=",
"Time",
".",
"now",
".",
"to_i",
"end",
"if",
"expanded",
"save_expanded_stack",
"(",
"stack",
".",
"id",
",",
"stack",
".",
"to_json",
")",
"end",
"rescue",
"=>",
"e",
"logger",
".",
"error",
"\"Stack expansion failed (#{stack.id}) - #{e.class}: #{e}\"",
"end",
"else",
"logger",
".",
"info",
"\"Stack has been cached within expand interval. Expansion prevented. (#{stack.id})\"",
"end",
"end"
] | Expand all lazy loaded attributes within stack
@param stack [Miasma::Models::Orchestration::Stack] | [
"Expand",
"all",
"lazy",
"loaded",
"attributes",
"within",
"stack"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/provider.rb#L153-L173 | train |
sparkleformation/sfn | lib/sfn/provider.rb | Sfn.Provider.fetch_stacks | def fetch_stacks(stack_id = nil)
cache.locked_action(:stacks_lock) do
logger.info "Lock aquired for stack update. Requesting stacks from upstream. (#{Thread.current})"
if stack_id
single_stack = connection.stacks.get(stack_id)
stacks = single_stack ? {single_stack.id => single_stack} : {}
else
stacks = Hash[
connection.stacks.reload.all.map do |stack|
[stack.id, stack.attributes]
end
]
end
if cache[:stacks].value
existing_stacks = MultiJson.load(cache[:stacks].value)
# Force common types
stacks = MultiJson.load(MultiJson.dump(stacks))
if stack_id
stacks = existing_stacks.to_smash.deep_merge(stacks)
else
# Remove stacks that have been deleted
stale_ids = existing_stacks.keys - stacks.keys
stacks = existing_stacks.to_smash.deep_merge(stacks)
stale_ids.each do |stale_id|
stacks.delete(stale_id)
end
end
end
cache[:stacks].value = stacks.to_json
logger.info "Stack list has been updated from upstream and cached locally"
end
@initial_fetch_complete = true
end | ruby | def fetch_stacks(stack_id = nil)
cache.locked_action(:stacks_lock) do
logger.info "Lock aquired for stack update. Requesting stacks from upstream. (#{Thread.current})"
if stack_id
single_stack = connection.stacks.get(stack_id)
stacks = single_stack ? {single_stack.id => single_stack} : {}
else
stacks = Hash[
connection.stacks.reload.all.map do |stack|
[stack.id, stack.attributes]
end
]
end
if cache[:stacks].value
existing_stacks = MultiJson.load(cache[:stacks].value)
# Force common types
stacks = MultiJson.load(MultiJson.dump(stacks))
if stack_id
stacks = existing_stacks.to_smash.deep_merge(stacks)
else
# Remove stacks that have been deleted
stale_ids = existing_stacks.keys - stacks.keys
stacks = existing_stacks.to_smash.deep_merge(stacks)
stale_ids.each do |stale_id|
stacks.delete(stale_id)
end
end
end
cache[:stacks].value = stacks.to_json
logger.info "Stack list has been updated from upstream and cached locally"
end
@initial_fetch_complete = true
end | [
"def",
"fetch_stacks",
"(",
"stack_id",
"=",
"nil",
")",
"cache",
".",
"locked_action",
"(",
":stacks_lock",
")",
"do",
"logger",
".",
"info",
"\"Lock aquired for stack update. Requesting stacks from upstream. (#{Thread.current})\"",
"if",
"stack_id",
"single_stack",
"=",
"connection",
".",
"stacks",
".",
"get",
"(",
"stack_id",
")",
"stacks",
"=",
"single_stack",
"?",
"{",
"single_stack",
".",
"id",
"=>",
"single_stack",
"}",
":",
"{",
"}",
"else",
"stacks",
"=",
"Hash",
"[",
"connection",
".",
"stacks",
".",
"reload",
".",
"all",
".",
"map",
"do",
"|",
"stack",
"|",
"[",
"stack",
".",
"id",
",",
"stack",
".",
"attributes",
"]",
"end",
"]",
"end",
"if",
"cache",
"[",
":stacks",
"]",
".",
"value",
"existing_stacks",
"=",
"MultiJson",
".",
"load",
"(",
"cache",
"[",
":stacks",
"]",
".",
"value",
")",
"# Force common types",
"stacks",
"=",
"MultiJson",
".",
"load",
"(",
"MultiJson",
".",
"dump",
"(",
"stacks",
")",
")",
"if",
"stack_id",
"stacks",
"=",
"existing_stacks",
".",
"to_smash",
".",
"deep_merge",
"(",
"stacks",
")",
"else",
"# Remove stacks that have been deleted",
"stale_ids",
"=",
"existing_stacks",
".",
"keys",
"-",
"stacks",
".",
"keys",
"stacks",
"=",
"existing_stacks",
".",
"to_smash",
".",
"deep_merge",
"(",
"stacks",
")",
"stale_ids",
".",
"each",
"do",
"|",
"stale_id",
"|",
"stacks",
".",
"delete",
"(",
"stale_id",
")",
"end",
"end",
"end",
"cache",
"[",
":stacks",
"]",
".",
"value",
"=",
"stacks",
".",
"to_json",
"logger",
".",
"info",
"\"Stack list has been updated from upstream and cached locally\"",
"end",
"@initial_fetch_complete",
"=",
"true",
"end"
] | Request stack information and store in cache
@return [TrueClass] | [
"Request",
"stack",
"information",
"and",
"store",
"in",
"cache"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/provider.rb#L178-L210 | train |
sparkleformation/sfn | lib/sfn/provider.rb | Sfn.Provider.update_stack_list! | def update_stack_list!
if updater.nil? || !updater.alive?
self.updater = Thread.new {
loop do
begin
fetch_stacks
sleep(stack_list_interval)
rescue => e
logger.error "Failure encountered on stack fetch: #{e.class} - #{e}"
end
end
}
true
else
false
end
end | ruby | def update_stack_list!
if updater.nil? || !updater.alive?
self.updater = Thread.new {
loop do
begin
fetch_stacks
sleep(stack_list_interval)
rescue => e
logger.error "Failure encountered on stack fetch: #{e.class} - #{e}"
end
end
}
true
else
false
end
end | [
"def",
"update_stack_list!",
"if",
"updater",
".",
"nil?",
"||",
"!",
"updater",
".",
"alive?",
"self",
".",
"updater",
"=",
"Thread",
".",
"new",
"{",
"loop",
"do",
"begin",
"fetch_stacks",
"sleep",
"(",
"stack_list_interval",
")",
"rescue",
"=>",
"e",
"logger",
".",
"error",
"\"Failure encountered on stack fetch: #{e.class} - #{e}\"",
"end",
"end",
"}",
"true",
"else",
"false",
"end",
"end"
] | Start async stack list update. Creates thread that loops every
`self.stack_list_interval` seconds and refreshes stack list in cache
@return [TrueClass, FalseClass] | [
"Start",
"async",
"stack",
"list",
"update",
".",
"Creates",
"thread",
"that",
"loops",
"every",
"self",
".",
"stack_list_interval",
"seconds",
"and",
"refreshes",
"stack",
"list",
"in",
"cache"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/provider.rb#L216-L232 | train |
sparkleformation/sfn | lib/sfn/command.rb | Sfn.Command.load_api_provider_extensions! | def load_api_provider_extensions!
if config.get(:credentials, :provider)
base_ext = Bogo::Utility.camel(config.get(:credentials, :provider)).to_sym
targ_ext = self.class.name.split("::").last
if ApiProvider.constants.include?(base_ext)
base_module = ApiProvider.const_get(base_ext)
ui.debug "Loading core provider extensions via `#{base_module}`"
extend base_module
if base_module.constants.include?(targ_ext)
targ_module = base_module.const_get(targ_ext)
ui.debug "Loading targeted provider extensions via `#{targ_module}`"
extend targ_module
end
true
end
end
end | ruby | def load_api_provider_extensions!
if config.get(:credentials, :provider)
base_ext = Bogo::Utility.camel(config.get(:credentials, :provider)).to_sym
targ_ext = self.class.name.split("::").last
if ApiProvider.constants.include?(base_ext)
base_module = ApiProvider.const_get(base_ext)
ui.debug "Loading core provider extensions via `#{base_module}`"
extend base_module
if base_module.constants.include?(targ_ext)
targ_module = base_module.const_get(targ_ext)
ui.debug "Loading targeted provider extensions via `#{targ_module}`"
extend targ_module
end
true
end
end
end | [
"def",
"load_api_provider_extensions!",
"if",
"config",
".",
"get",
"(",
":credentials",
",",
":provider",
")",
"base_ext",
"=",
"Bogo",
"::",
"Utility",
".",
"camel",
"(",
"config",
".",
"get",
"(",
":credentials",
",",
":provider",
")",
")",
".",
"to_sym",
"targ_ext",
"=",
"self",
".",
"class",
".",
"name",
".",
"split",
"(",
"\"::\"",
")",
".",
"last",
"if",
"ApiProvider",
".",
"constants",
".",
"include?",
"(",
"base_ext",
")",
"base_module",
"=",
"ApiProvider",
".",
"const_get",
"(",
"base_ext",
")",
"ui",
".",
"debug",
"\"Loading core provider extensions via `#{base_module}`\"",
"extend",
"base_module",
"if",
"base_module",
".",
"constants",
".",
"include?",
"(",
"targ_ext",
")",
"targ_module",
"=",
"base_module",
".",
"const_get",
"(",
"targ_ext",
")",
"ui",
".",
"debug",
"\"Loading targeted provider extensions via `#{targ_module}`\"",
"extend",
"targ_module",
"end",
"true",
"end",
"end",
"end"
] | Load API provider specific overrides to customize behavior
@return [TrueClass, FalseClass] | [
"Load",
"API",
"provider",
"specific",
"overrides",
"to",
"customize",
"behavior"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/command.rb#L68-L84 | train |
sparkleformation/sfn | lib/sfn/command.rb | Sfn.Command.discover_config | def discover_config(opts)
cwd = Dir.pwd.split(File::SEPARATOR)
detected_path = ""
until cwd.empty? || File.exists?(detected_path.to_s)
detected_path = Dir.glob(
(cwd + ["#{CONFIG_BASE_NAME}{#{VALID_CONFIG_EXTENSIONS.join(",")}}"]).join(
File::SEPARATOR
)
).first
cwd.pop
end
if opts.respond_to?(:fetch_option)
opts.fetch_option("config").value = detected_path if detected_path
else
opts["config"] = detected_path if detected_path
end
opts
end | ruby | def discover_config(opts)
cwd = Dir.pwd.split(File::SEPARATOR)
detected_path = ""
until cwd.empty? || File.exists?(detected_path.to_s)
detected_path = Dir.glob(
(cwd + ["#{CONFIG_BASE_NAME}{#{VALID_CONFIG_EXTENSIONS.join(",")}}"]).join(
File::SEPARATOR
)
).first
cwd.pop
end
if opts.respond_to?(:fetch_option)
opts.fetch_option("config").value = detected_path if detected_path
else
opts["config"] = detected_path if detected_path
end
opts
end | [
"def",
"discover_config",
"(",
"opts",
")",
"cwd",
"=",
"Dir",
".",
"pwd",
".",
"split",
"(",
"File",
"::",
"SEPARATOR",
")",
"detected_path",
"=",
"\"\"",
"until",
"cwd",
".",
"empty?",
"||",
"File",
".",
"exists?",
"(",
"detected_path",
".",
"to_s",
")",
"detected_path",
"=",
"Dir",
".",
"glob",
"(",
"(",
"cwd",
"+",
"[",
"\"#{CONFIG_BASE_NAME}{#{VALID_CONFIG_EXTENSIONS.join(\",\")}}\"",
"]",
")",
".",
"join",
"(",
"File",
"::",
"SEPARATOR",
")",
")",
".",
"first",
"cwd",
".",
"pop",
"end",
"if",
"opts",
".",
"respond_to?",
"(",
":fetch_option",
")",
"opts",
".",
"fetch_option",
"(",
"\"config\"",
")",
".",
"value",
"=",
"detected_path",
"if",
"detected_path",
"else",
"opts",
"[",
"\"config\"",
"]",
"=",
"detected_path",
"if",
"detected_path",
"end",
"opts",
"end"
] | Start with current working directory and traverse to root
looking for a `.sfn` configuration file
@param opts [Slop]
@return [Slop] | [
"Start",
"with",
"current",
"working",
"directory",
"and",
"traverse",
"to",
"root",
"looking",
"for",
"a",
".",
"sfn",
"configuration",
"file"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/command.rb#L91-L108 | train |
sparkleformation/sfn | lib/sfn/cache.rb | Sfn.Cache.init | def init(name, kind, args = {})
get_storage(self.class.type, kind, name, args)
true
end | ruby | def init(name, kind, args = {})
get_storage(self.class.type, kind, name, args)
true
end | [
"def",
"init",
"(",
"name",
",",
"kind",
",",
"args",
"=",
"{",
"}",
")",
"get_storage",
"(",
"self",
".",
"class",
".",
"type",
",",
"kind",
",",
"name",
",",
"args",
")",
"true",
"end"
] | Create new instance
@param key [String, Array]
Initialize a new data type
@param name [Symbol] name of data
@param kind [Symbol] data type
@param args [Hash] options for data type | [
"Create",
"new",
"instance"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/cache.rb#L93-L96 | train |
sparkleformation/sfn | lib/sfn/cache.rb | Sfn.Cache.get_storage | def get_storage(store_type, data_type, name, args = {})
full_name = "#{key}_#{name}"
result = nil
case store_type.to_sym
when :redis
result = get_redis_storage(data_type, full_name.to_s, args)
when :local
@_local_cache ||= {}
unless @_local_cache[full_name.to_s]
@_local_cache[full_name.to_s] = get_local_storage(data_type, full_name.to_s, args)
end
result = @_local_cache[full_name.to_s]
else
raise TypeError.new("Unsupported caching storage type encountered: #{store_type}")
end
unless full_name == "#{key}_registry_#{key}"
registry[name.to_s] = data_type
end
result
end | ruby | def get_storage(store_type, data_type, name, args = {})
full_name = "#{key}_#{name}"
result = nil
case store_type.to_sym
when :redis
result = get_redis_storage(data_type, full_name.to_s, args)
when :local
@_local_cache ||= {}
unless @_local_cache[full_name.to_s]
@_local_cache[full_name.to_s] = get_local_storage(data_type, full_name.to_s, args)
end
result = @_local_cache[full_name.to_s]
else
raise TypeError.new("Unsupported caching storage type encountered: #{store_type}")
end
unless full_name == "#{key}_registry_#{key}"
registry[name.to_s] = data_type
end
result
end | [
"def",
"get_storage",
"(",
"store_type",
",",
"data_type",
",",
"name",
",",
"args",
"=",
"{",
"}",
")",
"full_name",
"=",
"\"#{key}_#{name}\"",
"result",
"=",
"nil",
"case",
"store_type",
".",
"to_sym",
"when",
":redis",
"result",
"=",
"get_redis_storage",
"(",
"data_type",
",",
"full_name",
".",
"to_s",
",",
"args",
")",
"when",
":local",
"@_local_cache",
"||=",
"{",
"}",
"unless",
"@_local_cache",
"[",
"full_name",
".",
"to_s",
"]",
"@_local_cache",
"[",
"full_name",
".",
"to_s",
"]",
"=",
"get_local_storage",
"(",
"data_type",
",",
"full_name",
".",
"to_s",
",",
"args",
")",
"end",
"result",
"=",
"@_local_cache",
"[",
"full_name",
".",
"to_s",
"]",
"else",
"raise",
"TypeError",
".",
"new",
"(",
"\"Unsupported caching storage type encountered: #{store_type}\"",
")",
"end",
"unless",
"full_name",
"==",
"\"#{key}_registry_#{key}\"",
"registry",
"[",
"name",
".",
"to_s",
"]",
"=",
"data_type",
"end",
"result",
"end"
] | Fetch item from storage
@param store_type [Symbol]
@param data_type [Symbol]
@param name [Symbol] name of data
@param args [Hash] options for underlying storage
@return [Object] | [
"Fetch",
"item",
"from",
"storage"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/cache.rb#L132-L151 | train |
sparkleformation/sfn | lib/sfn/cache.rb | Sfn.Cache.get_redis_storage | def get_redis_storage(data_type, full_name, args = {})
self.class.redis_ping!
case data_type.to_sym
when :array
Redis::List.new(full_name, {:marshal => true}.merge(args))
when :hash
Redis::HashKey.new(full_name)
when :value
Redis::Value.new(full_name, {:marshal => true}.merge(args))
when :lock
Redis::Lock.new(full_name, {:expiration => 60, :timeout => 0.1}.merge(args))
when :stamped
Stamped.new(full_name.sub("#{key}_", "").to_sym, get_redis_storage(:value, full_name), self)
else
raise TypeError.new("Unsupported caching data type encountered: #{data_type}")
end
end | ruby | def get_redis_storage(data_type, full_name, args = {})
self.class.redis_ping!
case data_type.to_sym
when :array
Redis::List.new(full_name, {:marshal => true}.merge(args))
when :hash
Redis::HashKey.new(full_name)
when :value
Redis::Value.new(full_name, {:marshal => true}.merge(args))
when :lock
Redis::Lock.new(full_name, {:expiration => 60, :timeout => 0.1}.merge(args))
when :stamped
Stamped.new(full_name.sub("#{key}_", "").to_sym, get_redis_storage(:value, full_name), self)
else
raise TypeError.new("Unsupported caching data type encountered: #{data_type}")
end
end | [
"def",
"get_redis_storage",
"(",
"data_type",
",",
"full_name",
",",
"args",
"=",
"{",
"}",
")",
"self",
".",
"class",
".",
"redis_ping!",
"case",
"data_type",
".",
"to_sym",
"when",
":array",
"Redis",
"::",
"List",
".",
"new",
"(",
"full_name",
",",
"{",
":marshal",
"=>",
"true",
"}",
".",
"merge",
"(",
"args",
")",
")",
"when",
":hash",
"Redis",
"::",
"HashKey",
".",
"new",
"(",
"full_name",
")",
"when",
":value",
"Redis",
"::",
"Value",
".",
"new",
"(",
"full_name",
",",
"{",
":marshal",
"=>",
"true",
"}",
".",
"merge",
"(",
"args",
")",
")",
"when",
":lock",
"Redis",
"::",
"Lock",
".",
"new",
"(",
"full_name",
",",
"{",
":expiration",
"=>",
"60",
",",
":timeout",
"=>",
"0.1",
"}",
".",
"merge",
"(",
"args",
")",
")",
"when",
":stamped",
"Stamped",
".",
"new",
"(",
"full_name",
".",
"sub",
"(",
"\"#{key}_\"",
",",
"\"\"",
")",
".",
"to_sym",
",",
"get_redis_storage",
"(",
":value",
",",
"full_name",
")",
",",
"self",
")",
"else",
"raise",
"TypeError",
".",
"new",
"(",
"\"Unsupported caching data type encountered: #{data_type}\"",
")",
"end",
"end"
] | Fetch item from redis storage
@param data_type [Symbol]
@param full_name [Symbol]
@param args [Hash]
@return [Object] | [
"Fetch",
"item",
"from",
"redis",
"storage"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/cache.rb#L159-L175 | train |
sparkleformation/sfn | lib/sfn/cache.rb | Sfn.Cache.get_local_storage | def get_local_storage(data_type, full_name, args = {})
@storage ||= {}
@storage[full_name] ||= case data_type.to_sym
when :array
[]
when :hash
{}
when :value
LocalValue.new
when :lock
LocalLock.new(full_name, {:expiration => 60, :timeout => 0.1}.merge(args))
when :stamped
Stamped.new(full_name.sub("#{key}_", "").to_sym, get_local_storage(:value, full_name), self)
else
raise TypeError.new("Unsupported caching data type encountered: #{data_type}")
end
end | ruby | def get_local_storage(data_type, full_name, args = {})
@storage ||= {}
@storage[full_name] ||= case data_type.to_sym
when :array
[]
when :hash
{}
when :value
LocalValue.new
when :lock
LocalLock.new(full_name, {:expiration => 60, :timeout => 0.1}.merge(args))
when :stamped
Stamped.new(full_name.sub("#{key}_", "").to_sym, get_local_storage(:value, full_name), self)
else
raise TypeError.new("Unsupported caching data type encountered: #{data_type}")
end
end | [
"def",
"get_local_storage",
"(",
"data_type",
",",
"full_name",
",",
"args",
"=",
"{",
"}",
")",
"@storage",
"||=",
"{",
"}",
"@storage",
"[",
"full_name",
"]",
"||=",
"case",
"data_type",
".",
"to_sym",
"when",
":array",
"[",
"]",
"when",
":hash",
"{",
"}",
"when",
":value",
"LocalValue",
".",
"new",
"when",
":lock",
"LocalLock",
".",
"new",
"(",
"full_name",
",",
"{",
":expiration",
"=>",
"60",
",",
":timeout",
"=>",
"0.1",
"}",
".",
"merge",
"(",
"args",
")",
")",
"when",
":stamped",
"Stamped",
".",
"new",
"(",
"full_name",
".",
"sub",
"(",
"\"#{key}_\"",
",",
"\"\"",
")",
".",
"to_sym",
",",
"get_local_storage",
"(",
":value",
",",
"full_name",
")",
",",
"self",
")",
"else",
"raise",
"TypeError",
".",
"new",
"(",
"\"Unsupported caching data type encountered: #{data_type}\"",
")",
"end",
"end"
] | Fetch item from local storage
@param data_type [Symbol]
@param full_name [Symbol]
@param args [Hash]
@return [Object]
@todo make proper singleton for local storage | [
"Fetch",
"item",
"from",
"local",
"storage"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/cache.rb#L184-L200 | train |
sparkleformation/sfn | lib/sfn/cache.rb | Sfn.Cache.time_check_allow? | def time_check_allow?(key, stamp)
Time.now.to_i - stamp.to_i > apply_limit(key)
end | ruby | def time_check_allow?(key, stamp)
Time.now.to_i - stamp.to_i > apply_limit(key)
end | [
"def",
"time_check_allow?",
"(",
"key",
",",
"stamp",
")",
"Time",
".",
"now",
".",
"to_i",
"-",
"stamp",
".",
"to_i",
">",
"apply_limit",
"(",
"key",
")",
"end"
] | Check if cache time has expired
@param key [String, Symbol] value key
@param stamp [Time, Integer]
@return [TrueClass, FalseClass] | [
"Check",
"if",
"cache",
"time",
"has",
"expired"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/cache.rb#L238-L240 | train |
sparkleformation/sfn | lib/sfn/cache.rb | Sfn.Cache.apply_limit | def apply_limit(kind, seconds = nil)
@apply_limit ||= {}
if seconds
@apply_limit[kind.to_sym] = seconds.to_i
end
@apply_limit[kind.to_sym].to_i
end | ruby | def apply_limit(kind, seconds = nil)
@apply_limit ||= {}
if seconds
@apply_limit[kind.to_sym] = seconds.to_i
end
@apply_limit[kind.to_sym].to_i
end | [
"def",
"apply_limit",
"(",
"kind",
",",
"seconds",
"=",
"nil",
")",
"@apply_limit",
"||=",
"{",
"}",
"if",
"seconds",
"@apply_limit",
"[",
"kind",
".",
"to_sym",
"]",
"=",
"seconds",
".",
"to_i",
"end",
"@apply_limit",
"[",
"kind",
".",
"to_sym",
"]",
".",
"to_i",
"end"
] | Apply time limit for data type
@param kind [String, Symbol] data type
@param seconds [Integer]
return [Integer] | [
"Apply",
"time",
"limit",
"for",
"data",
"type"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/cache.rb#L247-L253 | train |
sparkleformation/sfn | lib/sfn/cache.rb | Sfn.Cache.locked_action | def locked_action(lock_name, raise_on_locked = false)
begin
self[lock_name].lock do
yield
end
rescue => e
if e.class.to_s.end_with?("Timeout")
raise if raise_on_locked
else
raise
end
end
end | ruby | def locked_action(lock_name, raise_on_locked = false)
begin
self[lock_name].lock do
yield
end
rescue => e
if e.class.to_s.end_with?("Timeout")
raise if raise_on_locked
else
raise
end
end
end | [
"def",
"locked_action",
"(",
"lock_name",
",",
"raise_on_locked",
"=",
"false",
")",
"begin",
"self",
"[",
"lock_name",
"]",
".",
"lock",
"do",
"yield",
"end",
"rescue",
"=>",
"e",
"if",
"e",
".",
"class",
".",
"to_s",
".",
"end_with?",
"(",
"\"Timeout\"",
")",
"raise",
"if",
"raise_on_locked",
"else",
"raise",
"end",
"end",
"end"
] | Perform action within lock
@param lock_name [String, Symbol] name of lock
@param raise_on_locked [TrueClass, FalseClass] raise execption if lock wait times out
@return [Object] result of yield | [
"Perform",
"action",
"within",
"lock"
] | 68dacff9b9a9cb3389d4b763566ca1e94659104b | https://github.com/sparkleformation/sfn/blob/68dacff9b9a9cb3389d4b763566ca1e94659104b/lib/sfn/cache.rb#L260-L272 | train |
liufengyun/hashdiff | lib/hashdiff/linear_compare_array.rb | HashDiff.LinearCompareArray.index_of_match_after_additions | def index_of_match_after_additions
return unless expected_additions > 0
(1..expected_additions).each do |i|
next_difference = item_difference(
old_array[old_index],
new_array[new_index + i],
old_index
)
return new_index + i if next_difference.empty?
end
nil
end | ruby | def index_of_match_after_additions
return unless expected_additions > 0
(1..expected_additions).each do |i|
next_difference = item_difference(
old_array[old_index],
new_array[new_index + i],
old_index
)
return new_index + i if next_difference.empty?
end
nil
end | [
"def",
"index_of_match_after_additions",
"return",
"unless",
"expected_additions",
">",
"0",
"(",
"1",
"..",
"expected_additions",
")",
".",
"each",
"do",
"|",
"i",
"|",
"next_difference",
"=",
"item_difference",
"(",
"old_array",
"[",
"old_index",
"]",
",",
"new_array",
"[",
"new_index",
"+",
"i",
"]",
",",
"old_index",
")",
"return",
"new_index",
"+",
"i",
"if",
"next_difference",
".",
"empty?",
"end",
"nil",
"end"
] | look ahead in the new array to see if the current item appears later
thereby having new items added | [
"look",
"ahead",
"in",
"the",
"new",
"array",
"to",
"see",
"if",
"the",
"current",
"item",
"appears",
"later",
"thereby",
"having",
"new",
"items",
"added"
] | ab58c062f4d0651d84e3f48d544ea88fd85aae54 | https://github.com/liufengyun/hashdiff/blob/ab58c062f4d0651d84e3f48d544ea88fd85aae54/lib/hashdiff/linear_compare_array.rb#L89-L103 | train |
liufengyun/hashdiff | lib/hashdiff/linear_compare_array.rb | HashDiff.LinearCompareArray.index_of_match_after_deletions | def index_of_match_after_deletions
return unless expected_additions < 0
(1..(expected_additions.abs)).each do |i|
next_difference = item_difference(
old_array[old_index + i],
new_array[new_index],
old_index
)
return old_index + i if next_difference.empty?
end
nil
end | ruby | def index_of_match_after_deletions
return unless expected_additions < 0
(1..(expected_additions.abs)).each do |i|
next_difference = item_difference(
old_array[old_index + i],
new_array[new_index],
old_index
)
return old_index + i if next_difference.empty?
end
nil
end | [
"def",
"index_of_match_after_deletions",
"return",
"unless",
"expected_additions",
"<",
"0",
"(",
"1",
"..",
"(",
"expected_additions",
".",
"abs",
")",
")",
".",
"each",
"do",
"|",
"i",
"|",
"next_difference",
"=",
"item_difference",
"(",
"old_array",
"[",
"old_index",
"+",
"i",
"]",
",",
"new_array",
"[",
"new_index",
"]",
",",
"old_index",
")",
"return",
"old_index",
"+",
"i",
"if",
"next_difference",
".",
"empty?",
"end",
"nil",
"end"
] | look ahead in the old array to see if the current item appears later
thereby having items removed | [
"look",
"ahead",
"in",
"the",
"old",
"array",
"to",
"see",
"if",
"the",
"current",
"item",
"appears",
"later",
"thereby",
"having",
"items",
"removed"
] | ab58c062f4d0651d84e3f48d544ea88fd85aae54 | https://github.com/liufengyun/hashdiff/blob/ab58c062f4d0651d84e3f48d544ea88fd85aae54/lib/hashdiff/linear_compare_array.rb#L107-L121 | train |
nedap/mysql-binuuid-rails | lib/mysql-binuuid/type.rb | MySQLBinUUID.Type.cast | def cast(value)
if value.is_a?(MySQLBinUUID::Type::Data)
# It could be a Data object, in which case we should add dashes to the
# string value from there.
add_dashes(value.to_s)
elsif value.is_a?(String) && value.encoding == Encoding::ASCII_8BIT && strip_dashes(value).length != 32
# We cannot unpack something that looks like a UUID, with or without
# dashes. Not entirely sure why ActiveRecord does a weird combination of
# cast and serialize before anything needs to be saved..
undashed_uuid = value.unpack1('H*')
add_dashes(undashed_uuid.to_s)
else
super
end
end | ruby | def cast(value)
if value.is_a?(MySQLBinUUID::Type::Data)
# It could be a Data object, in which case we should add dashes to the
# string value from there.
add_dashes(value.to_s)
elsif value.is_a?(String) && value.encoding == Encoding::ASCII_8BIT && strip_dashes(value).length != 32
# We cannot unpack something that looks like a UUID, with or without
# dashes. Not entirely sure why ActiveRecord does a weird combination of
# cast and serialize before anything needs to be saved..
undashed_uuid = value.unpack1('H*')
add_dashes(undashed_uuid.to_s)
else
super
end
end | [
"def",
"cast",
"(",
"value",
")",
"if",
"value",
".",
"is_a?",
"(",
"MySQLBinUUID",
"::",
"Type",
"::",
"Data",
")",
"# It could be a Data object, in which case we should add dashes to the",
"# string value from there.",
"add_dashes",
"(",
"value",
".",
"to_s",
")",
"elsif",
"value",
".",
"is_a?",
"(",
"String",
")",
"&&",
"value",
".",
"encoding",
"==",
"Encoding",
"::",
"ASCII_8BIT",
"&&",
"strip_dashes",
"(",
"value",
")",
".",
"length",
"!=",
"32",
"# We cannot unpack something that looks like a UUID, with or without",
"# dashes. Not entirely sure why ActiveRecord does a weird combination of",
"# cast and serialize before anything needs to be saved..",
"undashed_uuid",
"=",
"value",
".",
"unpack1",
"(",
"'H*'",
")",
"add_dashes",
"(",
"undashed_uuid",
".",
"to_s",
")",
"else",
"super",
"end",
"end"
] | Invoked when a value that is returned from the database needs to be
displayed into something readable again. | [
"Invoked",
"when",
"a",
"value",
"that",
"is",
"returned",
"from",
"the",
"database",
"needs",
"to",
"be",
"displayed",
"into",
"something",
"readable",
"again",
"."
] | d418e1cee3a58ad3f222054f92d0404dc19ef464 | https://github.com/nedap/mysql-binuuid-rails/blob/d418e1cee3a58ad3f222054f92d0404dc19ef464/lib/mysql-binuuid/type.rb#L11-L25 | train |
nedap/mysql-binuuid-rails | lib/mysql-binuuid/type.rb | MySQLBinUUID.Type.serialize | def serialize(value)
return if value.nil?
undashed_uuid = strip_dashes(value)
# To avoid SQL injection, verify that it looks like a UUID. ActiveRecord
# does not explicity escape the Binary data type. escaping is implicit as
# the Binary data type always converts its value to a hex string.
unless valid_undashed_uuid?(undashed_uuid)
raise MySQLBinUUID::InvalidUUID, "#{value} is not a valid UUID"
end
Data.new(undashed_uuid)
end | ruby | def serialize(value)
return if value.nil?
undashed_uuid = strip_dashes(value)
# To avoid SQL injection, verify that it looks like a UUID. ActiveRecord
# does not explicity escape the Binary data type. escaping is implicit as
# the Binary data type always converts its value to a hex string.
unless valid_undashed_uuid?(undashed_uuid)
raise MySQLBinUUID::InvalidUUID, "#{value} is not a valid UUID"
end
Data.new(undashed_uuid)
end | [
"def",
"serialize",
"(",
"value",
")",
"return",
"if",
"value",
".",
"nil?",
"undashed_uuid",
"=",
"strip_dashes",
"(",
"value",
")",
"# To avoid SQL injection, verify that it looks like a UUID. ActiveRecord",
"# does not explicity escape the Binary data type. escaping is implicit as",
"# the Binary data type always converts its value to a hex string.",
"unless",
"valid_undashed_uuid?",
"(",
"undashed_uuid",
")",
"raise",
"MySQLBinUUID",
"::",
"InvalidUUID",
",",
"\"#{value} is not a valid UUID\"",
"end",
"Data",
".",
"new",
"(",
"undashed_uuid",
")",
"end"
] | Invoked when the provided value needs to be serialized before storing
it to the database. | [
"Invoked",
"when",
"the",
"provided",
"value",
"needs",
"to",
"be",
"serialized",
"before",
"storing",
"it",
"to",
"the",
"database",
"."
] | d418e1cee3a58ad3f222054f92d0404dc19ef464 | https://github.com/nedap/mysql-binuuid-rails/blob/d418e1cee3a58ad3f222054f92d0404dc19ef464/lib/mysql-binuuid/type.rb#L29-L41 | train |
nedap/mysql-binuuid-rails | lib/mysql-binuuid/type.rb | MySQLBinUUID.Type.add_dashes | def add_dashes(uuid)
return uuid if uuid =~ /\-/
[uuid[0..7], uuid[8..11], uuid[12..15], uuid[16..19], uuid[20..-1]].join("-")
end | ruby | def add_dashes(uuid)
return uuid if uuid =~ /\-/
[uuid[0..7], uuid[8..11], uuid[12..15], uuid[16..19], uuid[20..-1]].join("-")
end | [
"def",
"add_dashes",
"(",
"uuid",
")",
"return",
"uuid",
"if",
"uuid",
"=~",
"/",
"\\-",
"/",
"[",
"uuid",
"[",
"0",
"..",
"7",
"]",
",",
"uuid",
"[",
"8",
"..",
"11",
"]",
",",
"uuid",
"[",
"12",
"..",
"15",
"]",
",",
"uuid",
"[",
"16",
"..",
"19",
"]",
",",
"uuid",
"[",
"20",
"..",
"-",
"1",
"]",
"]",
".",
"join",
"(",
"\"-\"",
")",
"end"
] | A UUID consists of 5 groups of characters.
8 chars - 4 chars - 4 chars - 4 chars - 12 characters
This function re-introduces the dashes since we removed them during
serialization, so:
add_dashes("2b4a233152694c6e9d1e098804ab812b")
=> "2b4a2331-5269-4c6e-9d1e-098804ab812b" | [
"A",
"UUID",
"consists",
"of",
"5",
"groups",
"of",
"characters",
".",
"8",
"chars",
"-",
"4",
"chars",
"-",
"4",
"chars",
"-",
"4",
"chars",
"-",
"12",
"characters"
] | d418e1cee3a58ad3f222054f92d0404dc19ef464 | https://github.com/nedap/mysql-binuuid-rails/blob/d418e1cee3a58ad3f222054f92d0404dc19ef464/lib/mysql-binuuid/type.rb#L69-L72 | train |
halogenandtoast/oath | lib/oath/controller_helpers.rb | Oath.ControllerHelpers.sign_in | def sign_in user
Oath.config.sign_in_service.new(user, warden).perform.tap do |status|
if status && block_given?
yield
end
end
end | ruby | def sign_in user
Oath.config.sign_in_service.new(user, warden).perform.tap do |status|
if status && block_given?
yield
end
end
end | [
"def",
"sign_in",
"user",
"Oath",
".",
"config",
".",
"sign_in_service",
".",
"new",
"(",
"user",
",",
"warden",
")",
".",
"perform",
".",
"tap",
"do",
"|",
"status",
"|",
"if",
"status",
"&&",
"block_given?",
"yield",
"end",
"end",
"end"
] | Sign in a user
@note Uses the {Oath::Services::SignIn} service to create a session
@param user [User] the user object to sign in
@yield Yields to the block if the user is successfully signed in
@return [Object] returns the value from calling perform on the {Oath::Services::SignIn} service | [
"Sign",
"in",
"a",
"user"
] | f850ea5122d37285f0377675b9c084942086280f | https://github.com/halogenandtoast/oath/blob/f850ea5122d37285f0377675b9c084942086280f/lib/oath/controller_helpers.rb#L22-L28 | train |
halogenandtoast/oath | lib/oath/controller_helpers.rb | Oath.ControllerHelpers.sign_up | def sign_up user_params
Oath.config.sign_up_service.new(user_params).perform.tap do |status|
if status && block_given?
yield
end
end
end | ruby | def sign_up user_params
Oath.config.sign_up_service.new(user_params).perform.tap do |status|
if status && block_given?
yield
end
end
end | [
"def",
"sign_up",
"user_params",
"Oath",
".",
"config",
".",
"sign_up_service",
".",
"new",
"(",
"user_params",
")",
".",
"perform",
".",
"tap",
"do",
"|",
"status",
"|",
"if",
"status",
"&&",
"block_given?",
"yield",
"end",
"end",
"end"
] | Sign up a user
@note Uses the {Oath::Services::SignUp} service to create a user
@param user_params [Hash] params containing lookup and token fields
@yield Yields to the block if the user is signed up successfully
@return [Object] returns the value from calling perform on the {Oath::Services::SignUp} service | [
"Sign",
"up",
"a",
"user"
] | f850ea5122d37285f0377675b9c084942086280f | https://github.com/halogenandtoast/oath/blob/f850ea5122d37285f0377675b9c084942086280f/lib/oath/controller_helpers.rb#L46-L52 | train |
halogenandtoast/oath | lib/oath/controller_helpers.rb | Oath.ControllerHelpers.authenticate_session | def authenticate_session session_params, field_map = nil
token_field = Oath.config.user_token_field
params_hash = Oath.transform_params(session_params).symbolize_keys
password = params_hash.fetch(token_field)
user = Oath.lookup(params_hash.except(token_field), field_map)
authenticate(user, password)
end | ruby | def authenticate_session session_params, field_map = nil
token_field = Oath.config.user_token_field
params_hash = Oath.transform_params(session_params).symbolize_keys
password = params_hash.fetch(token_field)
user = Oath.lookup(params_hash.except(token_field), field_map)
authenticate(user, password)
end | [
"def",
"authenticate_session",
"session_params",
",",
"field_map",
"=",
"nil",
"token_field",
"=",
"Oath",
".",
"config",
".",
"user_token_field",
"params_hash",
"=",
"Oath",
".",
"transform_params",
"(",
"session_params",
")",
".",
"symbolize_keys",
"password",
"=",
"params_hash",
".",
"fetch",
"(",
"token_field",
")",
"user",
"=",
"Oath",
".",
"lookup",
"(",
"params_hash",
".",
"except",
"(",
"token_field",
")",
",",
"field_map",
")",
"authenticate",
"(",
"user",
",",
"password",
")",
"end"
] | Authenticates a session.
@note Uses the {Oath::Services::Authentication} service to verify the user's details
@param session_params [Hash] params containing lookup and token fields
@param field_map [Hash] Field map used for allowing users to sign in with multiple fields e.g. email and username
@return [User] if authentication succeeded
@return [nil] if authentication failed
@example Basic usage
class SessionsController < ApplicationController
def create
user = authenticate_session(session_params)
if sign_in(user)
redirect_to(root_path)
else
render :new
end
end
private
def session_params
params.require(:session).permit(:email, :password)
end
end
@example Using the field map to authenticate using multiple lookup fields
class SessionsController < ApplicationController
def create
user = authenticate_session(session_params, email_or_username: [:email, :username])
if sign_in(user)
redirect_to(root_path)
else
render :new
end
end
private
def session_params
params.require(:session).permit(:email_or_username, :password)
end
end | [
"Authenticates",
"a",
"session",
"."
] | f850ea5122d37285f0377675b9c084942086280f | https://github.com/halogenandtoast/oath/blob/f850ea5122d37285f0377675b9c084942086280f/lib/oath/controller_helpers.rb#L101-L107 | train |
halogenandtoast/oath | lib/oath/controller_helpers.rb | Oath.ControllerHelpers.authenticate | def authenticate user, password
Oath.config.authentication_service.new(user, password).perform
end | ruby | def authenticate user, password
Oath.config.authentication_service.new(user, password).perform
end | [
"def",
"authenticate",
"user",
",",
"password",
"Oath",
".",
"config",
".",
"authentication_service",
".",
"new",
"(",
"user",
",",
"password",
")",
".",
"perform",
"end"
] | Authenticates a user given a password
@note Uses the {Oath::Services::Authentication} service to verify the user's credentials
@param user [User] the user
@param password [String] the password
@return [User] if authentication succeeded
@return [nil] if authentication failed | [
"Authenticates",
"a",
"user",
"given",
"a",
"password"
] | f850ea5122d37285f0377675b9c084942086280f | https://github.com/halogenandtoast/oath/blob/f850ea5122d37285f0377675b9c084942086280f/lib/oath/controller_helpers.rb#L117-L119 | train |
halogenandtoast/oath | lib/oath/controller_helpers.rb | Oath.ControllerHelpers.reset_password | def reset_password user, password
Oath.config.password_reset_service.new(user, password).perform
end | ruby | def reset_password user, password
Oath.config.password_reset_service.new(user, password).perform
end | [
"def",
"reset_password",
"user",
",",
"password",
"Oath",
".",
"config",
".",
"password_reset_service",
".",
"new",
"(",
"user",
",",
"password",
")",
".",
"perform",
"end"
] | Resets a user's password
@note Uses the {Oath::Services::PasswordReset} service to change a user's password
@param user [User] the user
@param password [String] the password | [
"Resets",
"a",
"user",
"s",
"password"
] | f850ea5122d37285f0377675b9c084942086280f | https://github.com/halogenandtoast/oath/blob/f850ea5122d37285f0377675b9c084942086280f/lib/oath/controller_helpers.rb#L127-L129 | train |
halogenandtoast/oath | lib/oath/param_transformer.rb | Oath.ParamTransformer.to_h | def to_h
sanitized_params.each_with_object({}) do |(key, value), hash|
hash[key] = transform(key, value)
end
end | ruby | def to_h
sanitized_params.each_with_object({}) do |(key, value), hash|
hash[key] = transform(key, value)
end
end | [
"def",
"to_h",
"sanitized_params",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"(",
"key",
",",
"value",
")",
",",
"hash",
"|",
"hash",
"[",
"key",
"]",
"=",
"transform",
"(",
"key",
",",
"value",
")",
"end",
"end"
] | Initialize parameter transformer
@param params [ActionController::Parameters] parameters to be altered
Returns the transformed parameters | [
"Initialize",
"parameter",
"transformer"
] | f850ea5122d37285f0377675b9c084942086280f | https://github.com/halogenandtoast/oath/blob/f850ea5122d37285f0377675b9c084942086280f/lib/oath/param_transformer.rb#L14-L18 | train |
Skalar/google_distance_matrix | lib/google_distance_matrix/client.rb | GoogleDistanceMatrix.Client.get | def get(url, instrumentation: {}, **_options)
uri = URI.parse url
response = ActiveSupport::Notifications.instrument(
'client_request_matrix_data.google_distance_matrix', instrumentation
) do
Net::HTTP.get_response uri
end
handle response, url
rescue Timeout::Error => error
raise ServerError, error
end | ruby | def get(url, instrumentation: {}, **_options)
uri = URI.parse url
response = ActiveSupport::Notifications.instrument(
'client_request_matrix_data.google_distance_matrix', instrumentation
) do
Net::HTTP.get_response uri
end
handle response, url
rescue Timeout::Error => error
raise ServerError, error
end | [
"def",
"get",
"(",
"url",
",",
"instrumentation",
":",
"{",
"}",
",",
"**",
"_options",
")",
"uri",
"=",
"URI",
".",
"parse",
"url",
"response",
"=",
"ActiveSupport",
"::",
"Notifications",
".",
"instrument",
"(",
"'client_request_matrix_data.google_distance_matrix'",
",",
"instrumentation",
")",
"do",
"Net",
"::",
"HTTP",
".",
"get_response",
"uri",
"end",
"handle",
"response",
",",
"url",
"rescue",
"Timeout",
"::",
"Error",
"=>",
"error",
"raise",
"ServerError",
",",
"error",
"end"
] | Make a GET request to given URL
@param url The URL to Google's API we'll make a request to
@param instrumentation A hash with instrumentation payload
@param options Other options we don't care about, for example we'll capture
`configuration` option which we are not using, but the ClientCache
is using.
@return Hash with data from parsed response body | [
"Make",
"a",
"GET",
"request",
"to",
"given",
"URL"
] | 2bd0eb8eaa430d0a3fa3c047dab303683e7692fe | https://github.com/Skalar/google_distance_matrix/blob/2bd0eb8eaa430d0a3fa3c047dab303683e7692fe/lib/google_distance_matrix/client.rb#L23-L35 | train |
Skalar/google_distance_matrix | lib/google_distance_matrix/polyline_encoder.rb | GoogleDistanceMatrix.PolylineEncoder.encode | def encode
return @encoded if @encoded
deltas = @delta.deltas_rounded @array_of_lat_lng_pairs
chars_array = deltas.map { |v| @value_encoder.encode v }
@encoded = chars_array.join
end | ruby | def encode
return @encoded if @encoded
deltas = @delta.deltas_rounded @array_of_lat_lng_pairs
chars_array = deltas.map { |v| @value_encoder.encode v }
@encoded = chars_array.join
end | [
"def",
"encode",
"return",
"@encoded",
"if",
"@encoded",
"deltas",
"=",
"@delta",
".",
"deltas_rounded",
"@array_of_lat_lng_pairs",
"chars_array",
"=",
"deltas",
".",
"map",
"{",
"|",
"v",
"|",
"@value_encoder",
".",
"encode",
"v",
"}",
"@encoded",
"=",
"chars_array",
".",
"join",
"end"
] | Initialize a new encoder
Arguments
array_of_lat_lng_pairs - The array of lat/lng pairs, like [[lat, lng], [lat, lng], ..etc]
delta - An object responsible for rounding and calculate the deltas
between the given lat/lng pairs.
value_encoder - After deltas are calculated each value is passed to the encoder
to be encoded in to ASCII characters
@see ::encode
Encode and returns the encoded string | [
"Initialize",
"a",
"new",
"encoder"
] | 2bd0eb8eaa430d0a3fa3c047dab303683e7692fe | https://github.com/Skalar/google_distance_matrix/blob/2bd0eb8eaa430d0a3fa3c047dab303683e7692fe/lib/google_distance_matrix/polyline_encoder.rb#L38-L45 | train |
rocketjob/rocketjob_mission_control | app/models/rocket_job_mission_control/query.rb | RocketJobMissionControl.Query.unsorted_query | def unsorted_query
records = scope
# Text Search
if search_term
escaped = Regexp.escape(search_term)
regexp = Regexp.new(escaped, Regexp::IGNORECASE)
if search_columns.size == 1
records = records.where(search_columns.first => regexp)
else
cols = search_columns.collect { |col| {col => regexp} }
records = records.where('$or' => cols)
end
end
# Pagination
if start && page_size
records = records.skip(start).limit(page_size)
end
records
end | ruby | def unsorted_query
records = scope
# Text Search
if search_term
escaped = Regexp.escape(search_term)
regexp = Regexp.new(escaped, Regexp::IGNORECASE)
if search_columns.size == 1
records = records.where(search_columns.first => regexp)
else
cols = search_columns.collect { |col| {col => regexp} }
records = records.where('$or' => cols)
end
end
# Pagination
if start && page_size
records = records.skip(start).limit(page_size)
end
records
end | [
"def",
"unsorted_query",
"records",
"=",
"scope",
"# Text Search",
"if",
"search_term",
"escaped",
"=",
"Regexp",
".",
"escape",
"(",
"search_term",
")",
"regexp",
"=",
"Regexp",
".",
"new",
"(",
"escaped",
",",
"Regexp",
"::",
"IGNORECASE",
")",
"if",
"search_columns",
".",
"size",
"==",
"1",
"records",
"=",
"records",
".",
"where",
"(",
"search_columns",
".",
"first",
"=>",
"regexp",
")",
"else",
"cols",
"=",
"search_columns",
".",
"collect",
"{",
"|",
"col",
"|",
"{",
"col",
"=>",
"regexp",
"}",
"}",
"records",
"=",
"records",
".",
"where",
"(",
"'$or'",
"=>",
"cols",
")",
"end",
"end",
"# Pagination",
"if",
"start",
"&&",
"page_size",
"records",
"=",
"records",
".",
"skip",
"(",
"start",
")",
".",
"limit",
"(",
"page_size",
")",
"end",
"records",
"end"
] | Returns the filtered query expression | [
"Returns",
"the",
"filtered",
"query",
"expression"
] | 5b740662e97bbdcd4d9c3de4909a8e56149469f5 | https://github.com/rocketjob/rocketjob_mission_control/blob/5b740662e97bbdcd4d9c3de4909a8e56149469f5/app/models/rocket_job_mission_control/query.rb#L35-L54 | train |
rocketjob/rocketjob_mission_control | app/helpers/rocket_job_mission_control/application_helper.rb | RocketJobMissionControl.ApplicationHelper.editable_field_html | def editable_field_html(klass, field_name, value, f, include_nil_selectors = false)
# When editing a job the values are of the correct type.
# When editing a dirmon entry values are strings.
field = klass.fields[field_name.to_s]
return unless field && field.type
placeholder = field.default_val
placeholder = nil if placeholder.is_a?(Proc)
case field.type.name
when 'Symbol', 'String', 'Integer'
options = extract_inclusion_values(klass, field_name)
str = "[#{field.type.name}]\n".html_safe
if options
str + f.select(field_name, options, { include_blank: options.include?(nil) || include_nil_selectors, selected: value }, { class: 'selectize form-control' })
else
if field.type.name == 'Integer'
str + f.number_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
else
str + f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
end
end
when 'Hash'
"[JSON Hash]\n".html_safe +
f.text_field(field_name, value: value ? value.to_json : '', class: 'form-control', placeholder: '{"key1":"value1", "key2":"value2", "key3":"value3"}')
when 'Array'
options = Array(value)
"[Array]\n".html_safe +
f.select(field_name, options_for_select(options, options), { include_hidden: false }, { class: 'selectize form-control', multiple: true })
when 'Mongoid::Boolean'
name = "#{field_name}_true".to_sym
value = value.to_s
str = '<div class="radio-buttons">'.html_safe
str << f.radio_button(field_name, 'true', checked: value == 'true')
str << ' '.html_safe + f.label(name, 'true')
str << ' '.html_safe + f.radio_button(field_name, 'false', checked: value == 'false')
str << ' '.html_safe + f.label(name, 'false')
# Allow this field to be unset (nil).
if include_nil_selectors
str << ' '.html_safe + f.radio_button(field_name, '', checked: value == '')
str << ' '.html_safe + f.label(name, 'nil')
end
str << '</div>'.html_safe
else
"[#{field.type.name}]".html_safe +
f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
end
end | ruby | def editable_field_html(klass, field_name, value, f, include_nil_selectors = false)
# When editing a job the values are of the correct type.
# When editing a dirmon entry values are strings.
field = klass.fields[field_name.to_s]
return unless field && field.type
placeholder = field.default_val
placeholder = nil if placeholder.is_a?(Proc)
case field.type.name
when 'Symbol', 'String', 'Integer'
options = extract_inclusion_values(klass, field_name)
str = "[#{field.type.name}]\n".html_safe
if options
str + f.select(field_name, options, { include_blank: options.include?(nil) || include_nil_selectors, selected: value }, { class: 'selectize form-control' })
else
if field.type.name == 'Integer'
str + f.number_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
else
str + f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
end
end
when 'Hash'
"[JSON Hash]\n".html_safe +
f.text_field(field_name, value: value ? value.to_json : '', class: 'form-control', placeholder: '{"key1":"value1", "key2":"value2", "key3":"value3"}')
when 'Array'
options = Array(value)
"[Array]\n".html_safe +
f.select(field_name, options_for_select(options, options), { include_hidden: false }, { class: 'selectize form-control', multiple: true })
when 'Mongoid::Boolean'
name = "#{field_name}_true".to_sym
value = value.to_s
str = '<div class="radio-buttons">'.html_safe
str << f.radio_button(field_name, 'true', checked: value == 'true')
str << ' '.html_safe + f.label(name, 'true')
str << ' '.html_safe + f.radio_button(field_name, 'false', checked: value == 'false')
str << ' '.html_safe + f.label(name, 'false')
# Allow this field to be unset (nil).
if include_nil_selectors
str << ' '.html_safe + f.radio_button(field_name, '', checked: value == '')
str << ' '.html_safe + f.label(name, 'nil')
end
str << '</div>'.html_safe
else
"[#{field.type.name}]".html_safe +
f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
end
end | [
"def",
"editable_field_html",
"(",
"klass",
",",
"field_name",
",",
"value",
",",
"f",
",",
"include_nil_selectors",
"=",
"false",
")",
"# When editing a job the values are of the correct type.",
"# When editing a dirmon entry values are strings.",
"field",
"=",
"klass",
".",
"fields",
"[",
"field_name",
".",
"to_s",
"]",
"return",
"unless",
"field",
"&&",
"field",
".",
"type",
"placeholder",
"=",
"field",
".",
"default_val",
"placeholder",
"=",
"nil",
"if",
"placeholder",
".",
"is_a?",
"(",
"Proc",
")",
"case",
"field",
".",
"type",
".",
"name",
"when",
"'Symbol'",
",",
"'String'",
",",
"'Integer'",
"options",
"=",
"extract_inclusion_values",
"(",
"klass",
",",
"field_name",
")",
"str",
"=",
"\"[#{field.type.name}]\\n\"",
".",
"html_safe",
"if",
"options",
"str",
"+",
"f",
".",
"select",
"(",
"field_name",
",",
"options",
",",
"{",
"include_blank",
":",
"options",
".",
"include?",
"(",
"nil",
")",
"||",
"include_nil_selectors",
",",
"selected",
":",
"value",
"}",
",",
"{",
"class",
":",
"'selectize form-control'",
"}",
")",
"else",
"if",
"field",
".",
"type",
".",
"name",
"==",
"'Integer'",
"str",
"+",
"f",
".",
"number_field",
"(",
"field_name",
",",
"value",
":",
"value",
",",
"class",
":",
"'form-control'",
",",
"placeholder",
":",
"placeholder",
")",
"else",
"str",
"+",
"f",
".",
"text_field",
"(",
"field_name",
",",
"value",
":",
"value",
",",
"class",
":",
"'form-control'",
",",
"placeholder",
":",
"placeholder",
")",
"end",
"end",
"when",
"'Hash'",
"\"[JSON Hash]\\n\"",
".",
"html_safe",
"+",
"f",
".",
"text_field",
"(",
"field_name",
",",
"value",
":",
"value",
"?",
"value",
".",
"to_json",
":",
"''",
",",
"class",
":",
"'form-control'",
",",
"placeholder",
":",
"'{\"key1\":\"value1\", \"key2\":\"value2\", \"key3\":\"value3\"}'",
")",
"when",
"'Array'",
"options",
"=",
"Array",
"(",
"value",
")",
"\"[Array]\\n\"",
".",
"html_safe",
"+",
"f",
".",
"select",
"(",
"field_name",
",",
"options_for_select",
"(",
"options",
",",
"options",
")",
",",
"{",
"include_hidden",
":",
"false",
"}",
",",
"{",
"class",
":",
"'selectize form-control'",
",",
"multiple",
":",
"true",
"}",
")",
"when",
"'Mongoid::Boolean'",
"name",
"=",
"\"#{field_name}_true\"",
".",
"to_sym",
"value",
"=",
"value",
".",
"to_s",
"str",
"=",
"'<div class=\"radio-buttons\">'",
".",
"html_safe",
"str",
"<<",
"f",
".",
"radio_button",
"(",
"field_name",
",",
"'true'",
",",
"checked",
":",
"value",
"==",
"'true'",
")",
"str",
"<<",
"' '",
".",
"html_safe",
"+",
"f",
".",
"label",
"(",
"name",
",",
"'true'",
")",
"str",
"<<",
"' '",
".",
"html_safe",
"+",
"f",
".",
"radio_button",
"(",
"field_name",
",",
"'false'",
",",
"checked",
":",
"value",
"==",
"'false'",
")",
"str",
"<<",
"' '",
".",
"html_safe",
"+",
"f",
".",
"label",
"(",
"name",
",",
"'false'",
")",
"# Allow this field to be unset (nil).",
"if",
"include_nil_selectors",
"str",
"<<",
"' '",
".",
"html_safe",
"+",
"f",
".",
"radio_button",
"(",
"field_name",
",",
"''",
",",
"checked",
":",
"value",
"==",
"''",
")",
"str",
"<<",
"' '",
".",
"html_safe",
"+",
"f",
".",
"label",
"(",
"name",
",",
"'nil'",
")",
"end",
"str",
"<<",
"'</div>'",
".",
"html_safe",
"else",
"\"[#{field.type.name}]\"",
".",
"html_safe",
"+",
"f",
".",
"text_field",
"(",
"field_name",
",",
"value",
":",
"value",
",",
"class",
":",
"'form-control'",
",",
"placeholder",
":",
"placeholder",
")",
"end",
"end"
] | Returns the editable field as html for use in editing dynamic fields from a Job class. | [
"Returns",
"the",
"editable",
"field",
"as",
"html",
"for",
"use",
"in",
"editing",
"dynamic",
"fields",
"from",
"a",
"Job",
"class",
"."
] | 5b740662e97bbdcd4d9c3de4909a8e56149469f5 | https://github.com/rocketjob/rocketjob_mission_control/blob/5b740662e97bbdcd4d9c3de4909a8e56149469f5/app/helpers/rocket_job_mission_control/application_helper.rb#L59-L107 | train |
rocketjob/rocketjob_mission_control | app/datatables/rocket_job_mission_control/jobs_datatable.rb | RocketJobMissionControl.JobsDatatable.map | def map(job)
index = 0
h = {}
@columns.each do |column|
h[index.to_s] = send(column[:value], job)
index += 1
end
h['DT_RowClass'] = "card callout callout-#{job_state(job)}"
h
end | ruby | def map(job)
index = 0
h = {}
@columns.each do |column|
h[index.to_s] = send(column[:value], job)
index += 1
end
h['DT_RowClass'] = "card callout callout-#{job_state(job)}"
h
end | [
"def",
"map",
"(",
"job",
")",
"index",
"=",
"0",
"h",
"=",
"{",
"}",
"@columns",
".",
"each",
"do",
"|",
"column",
"|",
"h",
"[",
"index",
".",
"to_s",
"]",
"=",
"send",
"(",
"column",
"[",
":value",
"]",
",",
"job",
")",
"index",
"+=",
"1",
"end",
"h",
"[",
"'DT_RowClass'",
"]",
"=",
"\"card callout callout-#{job_state(job)}\"",
"h",
"end"
] | Map the values for each column | [
"Map",
"the",
"values",
"for",
"each",
"column"
] | 5b740662e97bbdcd4d9c3de4909a8e56149469f5 | https://github.com/rocketjob/rocketjob_mission_control/blob/5b740662e97bbdcd4d9c3de4909a8e56149469f5/app/datatables/rocket_job_mission_control/jobs_datatable.rb#L82-L91 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/shared_string_table.rb | OoxmlParser.SharedStringTable.parse | def parse(file)
return nil unless File.exist?(file)
document = parse_xml(file)
node = document.xpath('*').first
node.attributes.each do |key, value|
case key
when 'count'
@count = value.value.to_i
when 'uniqueCount'
@unique_count = value.value.to_i
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'si'
@string_indexes << StringIndex.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(file)
return nil unless File.exist?(file)
document = parse_xml(file)
node = document.xpath('*').first
node.attributes.each do |key, value|
case key
when 'count'
@count = value.value.to_i
when 'uniqueCount'
@unique_count = value.value.to_i
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'si'
@string_indexes << StringIndex.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"file",
")",
"return",
"nil",
"unless",
"File",
".",
"exist?",
"(",
"file",
")",
"document",
"=",
"parse_xml",
"(",
"file",
")",
"node",
"=",
"document",
".",
"xpath",
"(",
"'*'",
")",
".",
"first",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'count'",
"@count",
"=",
"value",
".",
"value",
".",
"to_i",
"when",
"'uniqueCount'",
"@unique_count",
"=",
"value",
".",
"value",
".",
"to_i",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'si'",
"@string_indexes",
"<<",
"StringIndex",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse Shared string table file
@param file [String] path to file
@return [SharedStringTable] | [
"Parse",
"Shared",
"string",
"table",
"file"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/shared_string_table.rb#L20-L42 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group.rb | OoxmlParser.OldDocxGroup.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'shape'
element = OldDocxGroupElement.new(:shape)
element.object = OldDocxShape.new(parent: self).parse(node_child)
@elements << element
when 'wrap'
@properties.wrap = node_child.attribute('type').value.to_sym unless node_child.attribute('type').nil?
when 'group'
@elements << OldDocxGroup.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'shape'
element = OldDocxGroupElement.new(:shape)
element.object = OldDocxShape.new(parent: self).parse(node_child)
@elements << element
when 'wrap'
@properties.wrap = node_child.attribute('type').value.to_sym unless node_child.attribute('type').nil?
when 'group'
@elements << OldDocxGroup.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'shape'",
"element",
"=",
"OldDocxGroupElement",
".",
"new",
"(",
":shape",
")",
"element",
".",
"object",
"=",
"OldDocxShape",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"@elements",
"<<",
"element",
"when",
"'wrap'",
"@properties",
".",
"wrap",
"=",
"node_child",
".",
"attribute",
"(",
"'type'",
")",
".",
"value",
".",
"to_sym",
"unless",
"node_child",
".",
"attribute",
"(",
"'type'",
")",
".",
"nil?",
"when",
"'group'",
"@elements",
"<<",
"OldDocxGroup",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse OldDocxGroup object
@param node [Nokogiri::XML:Element] node to parse
@return [OldDocxGroup] result of parsing | [
"Parse",
"OldDocxGroup",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group.rb#L17-L31 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/plot_area.rb | OoxmlParser.PlotArea.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'barChart'
@bar_chart = CommonChartData.new(parent: self).parse(node_child)
when 'lineChart'
@line_chart = CommonChartData.new(parent: self).parse(node_child)
when 'areaChart'
@area_chart = CommonChartData.new(parent: self).parse(node_child)
when 'bubbleChart'
@bubble_chart = CommonChartData.new(parent: self).parse(node_child)
when 'doughnutChart'
@doughnut_chart = CommonChartData.new(parent: self).parse(node_child)
when 'pieChart'
@pie_chart = CommonChartData.new(parent: self).parse(node_child)
when 'scatterChart'
@scatter_chart = CommonChartData.new(parent: self).parse(node_child)
when 'radarChart'
@radar_chart = CommonChartData.new(parent: self).parse(node_child)
when 'stockChart'
@stock_chart = CommonChartData.new(parent: self).parse(node_child)
when 'surface3DChart'
@surface_3d_chart = CommonChartData.new(parent: self).parse(node_child)
when 'line3DChart'
@line_3d_chart = CommonChartData.new(parent: self).parse(node_child)
when 'bar3DChart'
@bar_3d_chart = CommonChartData.new(parent: self).parse(node_child)
when 'pie3DChart'
@pie_3d_chart = CommonChartData.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'barChart'
@bar_chart = CommonChartData.new(parent: self).parse(node_child)
when 'lineChart'
@line_chart = CommonChartData.new(parent: self).parse(node_child)
when 'areaChart'
@area_chart = CommonChartData.new(parent: self).parse(node_child)
when 'bubbleChart'
@bubble_chart = CommonChartData.new(parent: self).parse(node_child)
when 'doughnutChart'
@doughnut_chart = CommonChartData.new(parent: self).parse(node_child)
when 'pieChart'
@pie_chart = CommonChartData.new(parent: self).parse(node_child)
when 'scatterChart'
@scatter_chart = CommonChartData.new(parent: self).parse(node_child)
when 'radarChart'
@radar_chart = CommonChartData.new(parent: self).parse(node_child)
when 'stockChart'
@stock_chart = CommonChartData.new(parent: self).parse(node_child)
when 'surface3DChart'
@surface_3d_chart = CommonChartData.new(parent: self).parse(node_child)
when 'line3DChart'
@line_3d_chart = CommonChartData.new(parent: self).parse(node_child)
when 'bar3DChart'
@bar_3d_chart = CommonChartData.new(parent: self).parse(node_child)
when 'pie3DChart'
@pie_3d_chart = CommonChartData.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'barChart'",
"@bar_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'lineChart'",
"@line_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'areaChart'",
"@area_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'bubbleChart'",
"@bubble_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'doughnutChart'",
"@doughnut_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'pieChart'",
"@pie_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'scatterChart'",
"@scatter_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'radarChart'",
"@radar_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'stockChart'",
"@stock_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'surface3DChart'",
"@surface_3d_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'line3DChart'",
"@line_3d_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'bar3DChart'",
"@bar_3d_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'pie3DChart'",
"@pie_3d_chart",
"=",
"CommonChartData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse View3D object
@param node [Nokogiri::XML:Element] node to parse
@return [View3D] result of parsing | [
"Parse",
"View3D",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/plot_area.rb#L31-L63 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/chart/display_labels_properties.rb | OoxmlParser.DisplayLabelsProperties.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'dLblPos'
@position = value_to_symbol(node_child.attribute('val'))
when 'showLegendKey'
@show_legend_key = true if node_child.attribute('val').value == '1'
when 'showVal'
@show_values = true if node_child.attribute('val').value == '1'
when 'showCatName'
@show_category_name = option_enabled?(node_child)
when 'showSerName'
@show_series_name = option_enabled?(node_child)
when 'delete'
@delete = option_enabled?(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'dLblPos'
@position = value_to_symbol(node_child.attribute('val'))
when 'showLegendKey'
@show_legend_key = true if node_child.attribute('val').value == '1'
when 'showVal'
@show_values = true if node_child.attribute('val').value == '1'
when 'showCatName'
@show_category_name = option_enabled?(node_child)
when 'showSerName'
@show_series_name = option_enabled?(node_child)
when 'delete'
@delete = option_enabled?(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'dLblPos'",
"@position",
"=",
"value_to_symbol",
"(",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
")",
"when",
"'showLegendKey'",
"@show_legend_key",
"=",
"true",
"if",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"==",
"'1'",
"when",
"'showVal'",
"@show_values",
"=",
"true",
"if",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"==",
"'1'",
"when",
"'showCatName'",
"@show_category_name",
"=",
"option_enabled?",
"(",
"node_child",
")",
"when",
"'showSerName'",
"@show_series_name",
"=",
"option_enabled?",
"(",
"node_child",
")",
"when",
"'delete'",
"@delete",
"=",
"option_enabled?",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse DisplayLabelsProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [DisplayLabelsProperties] result of parsing | [
"Parse",
"DisplayLabelsProperties",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/display_labels_properties.rb#L21-L39 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_pattern_fill.rb | OoxmlParser.DocxPatternFill.parse | def parse(node)
@preset = node.attribute('prst').value.to_sym
node.xpath('*').each do |node_child|
case node_child.name
when 'fgClr'
@foreground_color = Color.new(parent: self).parse_color_model(node_child)
when 'bgClr'
@background_color = Color.new(parent: self).parse_color_model(node_child)
end
end
self
end | ruby | def parse(node)
@preset = node.attribute('prst').value.to_sym
node.xpath('*').each do |node_child|
case node_child.name
when 'fgClr'
@foreground_color = Color.new(parent: self).parse_color_model(node_child)
when 'bgClr'
@background_color = Color.new(parent: self).parse_color_model(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"@preset",
"=",
"node",
".",
"attribute",
"(",
"'prst'",
")",
".",
"value",
".",
"to_sym",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'fgClr'",
"@foreground_color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color_model",
"(",
"node_child",
")",
"when",
"'bgClr'",
"@background_color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color_model",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse DocxPatternFill object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxPatternFill] result of parsing | [
"Parse",
"DocxPatternFill",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_pattern_fill.rb#L9-L20 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_fill.rb | OoxmlParser.OldDocxShapeFill.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'id'
@file_reference = FileReference.new(parent: self).parse(node)
when 'type'
@stretching_type = case value.value
when 'frame'
:stretch
else
value.value.to_sym
end
when 'title'
@title = value.value.to_s
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'id'
@file_reference = FileReference.new(parent: self).parse(node)
when 'type'
@stretching_type = case value.value
when 'frame'
:stretch
else
value.value.to_sym
end
when 'title'
@title = value.value.to_s
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'id'",
"@file_reference",
"=",
"FileReference",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"when",
"'type'",
"@stretching_type",
"=",
"case",
"value",
".",
"value",
"when",
"'frame'",
":stretch",
"else",
"value",
".",
"value",
".",
"to_sym",
"end",
"when",
"'title'",
"@title",
"=",
"value",
".",
"value",
".",
"to_s",
"end",
"end",
"self",
"end"
] | Parse OldDocxShapeFill object
@param node [Nokogiri::XML:Element] node to parse
@return [OldDocxShapeFill] result of parsing | [
"Parse",
"OldDocxShapeFill",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_fill.rb#L11-L28 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb | OoxmlParser.ParagraphBorders.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'bottom'
@bottom = BordersProperties.new(parent: self).parse(node_child)
when 'left'
@left = BordersProperties.new(parent: self).parse(node_child)
when 'top'
@top = BordersProperties.new(parent: self).parse(node_child)
when 'right'
@right = BordersProperties.new(parent: self).parse(node_child)
when 'between'
@between = BordersProperties.new(parent: self).parse(node_child)
when 'bar'
@bar = BordersProperties.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'bottom'
@bottom = BordersProperties.new(parent: self).parse(node_child)
when 'left'
@left = BordersProperties.new(parent: self).parse(node_child)
when 'top'
@top = BordersProperties.new(parent: self).parse(node_child)
when 'right'
@right = BordersProperties.new(parent: self).parse(node_child)
when 'between'
@between = BordersProperties.new(parent: self).parse(node_child)
when 'bar'
@bar = BordersProperties.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'bottom'",
"@bottom",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'left'",
"@left",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'top'",
"@top",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'right'",
"@right",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'between'",
"@between",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'bar'",
"@bar",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse Paragraph Borders data
@param [Nokogiri::XML:Element] node with Paragraph Borders data
@return [ParagraphBorders] value of Paragraph Borders data | [
"Parse",
"Paragraph",
"Borders",
"data"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb#L34-L52 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_alternate_content.rb | OoxmlParser.PresentationAlternateContent.parse | def parse(node)
node.xpath('mc:Choice/*', 'xmlns:mc' => 'http://schemas.openxmlformats.org/markup-compatibility/2006').each do |node_child|
case node_child.name
when 'timing'
@timing = Timing.new(parent: self).parse(node_child)
when 'transition'
@transition = Transition.new(parent: self).parse(node_child)
when 'sp'
@elements << DocxShape.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('mc:Choice/*', 'xmlns:mc' => 'http://schemas.openxmlformats.org/markup-compatibility/2006').each do |node_child|
case node_child.name
when 'timing'
@timing = Timing.new(parent: self).parse(node_child)
when 'transition'
@transition = Transition.new(parent: self).parse(node_child)
when 'sp'
@elements << DocxShape.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'mc:Choice/*'",
",",
"'xmlns:mc'",
"=>",
"'http://schemas.openxmlformats.org/markup-compatibility/2006'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'timing'",
"@timing",
"=",
"Timing",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'transition'",
"@transition",
"=",
"Transition",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'sp'",
"@elements",
"<<",
"DocxShape",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse PresentationAlternateContent object
@param node [Nokogiri::XML:Element] node to parse
@return [PresentationAlternateContent] result of parsing | [
"Parse",
"PresentationAlternateContent",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_alternate_content.rb#L15-L27 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb | OoxmlParser.DocxColorScheme.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'solidFill'
@type = :solid
@color = Color.new(parent: self).parse_color_model(node_child)
when 'gradFill'
@type = :gradient
@color = GradientColor.new(parent: self).parse(node_child)
when 'noFill'
@color = :none
@type = :none
when 'srgbClr'
@color = Color.new(parent: self).parse_hex_string(node_child.attribute('val').value)
when 'schemeClr'
@color = Color.new(parent: self).parse_scheme_color(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'solidFill'
@type = :solid
@color = Color.new(parent: self).parse_color_model(node_child)
when 'gradFill'
@type = :gradient
@color = GradientColor.new(parent: self).parse(node_child)
when 'noFill'
@color = :none
@type = :none
when 'srgbClr'
@color = Color.new(parent: self).parse_hex_string(node_child.attribute('val').value)
when 'schemeClr'
@color = Color.new(parent: self).parse_scheme_color(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'solidFill'",
"@type",
"=",
":solid",
"@color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color_model",
"(",
"node_child",
")",
"when",
"'gradFill'",
"@type",
"=",
":gradient",
"@color",
"=",
"GradientColor",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'noFill'",
"@color",
"=",
":none",
"@type",
"=",
":none",
"when",
"'srgbClr'",
"@color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_hex_string",
"(",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
")",
"when",
"'schemeClr'",
"@color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_scheme_color",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse DocxColorScheme object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxColorScheme] result of parsing | [
"Parse",
"DocxColorScheme",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb#L15-L34 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb | OoxmlParser.DocumentBackground.parse | def parse(node)
@color1 = Color.new(parent: self).parse_hex_string(node.attribute('color').value)
node.xpath('v:background').each do |second_color|
@size = second_color.attribute('targetscreensize').value.sub(',', 'x') unless second_color.attribute('targetscreensize').nil?
second_color.xpath('*').each do |node_child|
case node_child.name
when 'fill'
@fill = Fill.new(parent: self).parse(node_child)
end
end
end
self
end | ruby | def parse(node)
@color1 = Color.new(parent: self).parse_hex_string(node.attribute('color').value)
node.xpath('v:background').each do |second_color|
@size = second_color.attribute('targetscreensize').value.sub(',', 'x') unless second_color.attribute('targetscreensize').nil?
second_color.xpath('*').each do |node_child|
case node_child.name
when 'fill'
@fill = Fill.new(parent: self).parse(node_child)
end
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"@color1",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_hex_string",
"(",
"node",
".",
"attribute",
"(",
"'color'",
")",
".",
"value",
")",
"node",
".",
"xpath",
"(",
"'v:background'",
")",
".",
"each",
"do",
"|",
"second_color",
"|",
"@size",
"=",
"second_color",
".",
"attribute",
"(",
"'targetscreensize'",
")",
".",
"value",
".",
"sub",
"(",
"','",
",",
"'x'",
")",
"unless",
"second_color",
".",
"attribute",
"(",
"'targetscreensize'",
")",
".",
"nil?",
"second_color",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'fill'",
"@fill",
"=",
"Fill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"end",
"self",
"end"
] | Parse DocumentBackground object
@param node [Nokogiri::XML:Element] node to parse
@return [DocumentBackground] result of parsing | [
"Parse",
"DocumentBackground",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb#L19-L31 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/ole_objects.rb | OoxmlParser.OleObjects.parse | def parse(node)
list = []
node.xpath('*').each do |node_child|
case node_child.name
when 'AlternateContent'
list << AlternateContent.new(parent: self).parse(node_child)
end
end
list
end | ruby | def parse(node)
list = []
node.xpath('*').each do |node_child|
case node_child.name
when 'AlternateContent'
list << AlternateContent.new(parent: self).parse(node_child)
end
end
list
end | [
"def",
"parse",
"(",
"node",
")",
"list",
"=",
"[",
"]",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'AlternateContent'",
"list",
"<<",
"AlternateContent",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"list",
"end"
] | Parse OleObjects object
@param node [Nokogiri::XML:Element] node to parse
@return [Array] list of OleObjects | [
"Parse",
"OleObjects",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/ole_objects.rb#L7-L16 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb | OoxmlParser.DocumentStyle.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'type'
@type = value.value.to_sym
when 'styleId'
@style_id = value.value
when 'default'
@default = attribute_enabled?(value.value)
end
end
node.xpath('*').each do |subnode|
case subnode.name
when 'name'
@name = subnode.attribute('val').value
when 'basedOn'
@based_on = subnode.attribute('val').value
when 'next'
@next_style = subnode.attribute('val').value
when 'rPr'
@run_properties = DocxParagraphRun.new(parent: self).parse_properties(subnode)
when 'pPr'
@paragraph_properties = ParagraphProperties.new(parent: self).parse(subnode)
when 'tblPr'
@table_properties = TableProperties.new(parent: self).parse(subnode)
when 'trPr'
@table_row_properties = TableRowProperties.new(parent: self).parse(subnode)
when 'tcPr'
@table_cell_properties = CellProperties.new(parent: self).parse(subnode)
when 'tblStylePr'
@table_style_properties_list << TableStyleProperties.new(parent: self).parse(subnode)
when 'qFormat'
@q_format = true
end
end
fill_empty_table_styles
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'type'
@type = value.value.to_sym
when 'styleId'
@style_id = value.value
when 'default'
@default = attribute_enabled?(value.value)
end
end
node.xpath('*').each do |subnode|
case subnode.name
when 'name'
@name = subnode.attribute('val').value
when 'basedOn'
@based_on = subnode.attribute('val').value
when 'next'
@next_style = subnode.attribute('val').value
when 'rPr'
@run_properties = DocxParagraphRun.new(parent: self).parse_properties(subnode)
when 'pPr'
@paragraph_properties = ParagraphProperties.new(parent: self).parse(subnode)
when 'tblPr'
@table_properties = TableProperties.new(parent: self).parse(subnode)
when 'trPr'
@table_row_properties = TableRowProperties.new(parent: self).parse(subnode)
when 'tcPr'
@table_cell_properties = CellProperties.new(parent: self).parse(subnode)
when 'tblStylePr'
@table_style_properties_list << TableStyleProperties.new(parent: self).parse(subnode)
when 'qFormat'
@q_format = true
end
end
fill_empty_table_styles
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'type'",
"@type",
"=",
"value",
".",
"value",
".",
"to_sym",
"when",
"'styleId'",
"@style_id",
"=",
"value",
".",
"value",
"when",
"'default'",
"@default",
"=",
"attribute_enabled?",
"(",
"value",
".",
"value",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"subnode",
"|",
"case",
"subnode",
".",
"name",
"when",
"'name'",
"@name",
"=",
"subnode",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'basedOn'",
"@based_on",
"=",
"subnode",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'next'",
"@next_style",
"=",
"subnode",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'rPr'",
"@run_properties",
"=",
"DocxParagraphRun",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_properties",
"(",
"subnode",
")",
"when",
"'pPr'",
"@paragraph_properties",
"=",
"ParagraphProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"subnode",
")",
"when",
"'tblPr'",
"@table_properties",
"=",
"TableProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"subnode",
")",
"when",
"'trPr'",
"@table_row_properties",
"=",
"TableRowProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"subnode",
")",
"when",
"'tcPr'",
"@table_cell_properties",
"=",
"CellProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"subnode",
")",
"when",
"'tblStylePr'",
"@table_style_properties_list",
"<<",
"TableStyleProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"subnode",
")",
"when",
"'qFormat'",
"@q_format",
"=",
"true",
"end",
"end",
"fill_empty_table_styles",
"self",
"end"
] | Parse single document style
@return [DocumentStyle] | [
"Parse",
"single",
"document",
"style"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb#L54-L91 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb | OoxmlParser.Worksheet.parse_drawing | def parse_drawing
drawing_node = parse_xml(OOXMLDocumentObject.current_xml)
drawing_node.xpath('xdr:wsDr/*').each do |drawing_node_child|
@drawings << XlsxDrawing.new(parent: self).parse(drawing_node_child)
end
end | ruby | def parse_drawing
drawing_node = parse_xml(OOXMLDocumentObject.current_xml)
drawing_node.xpath('xdr:wsDr/*').each do |drawing_node_child|
@drawings << XlsxDrawing.new(parent: self).parse(drawing_node_child)
end
end | [
"def",
"parse_drawing",
"drawing_node",
"=",
"parse_xml",
"(",
"OOXMLDocumentObject",
".",
"current_xml",
")",
"drawing_node",
".",
"xpath",
"(",
"'xdr:wsDr/*'",
")",
".",
"each",
"do",
"|",
"drawing_node_child",
"|",
"@drawings",
"<<",
"XlsxDrawing",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"drawing_node_child",
")",
"end",
"end"
] | Parse list of drawings in file | [
"Parse",
"list",
"of",
"drawings",
"in",
"file"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb#L59-L64 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb | OoxmlParser.Worksheet.parse_comments | def parse_comments
return unless relationships
comments_target = relationships.target_by_type('comment')
return if comments_target.empty?
comments_file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/#{comments_target.first.gsub('..', '')}"
@comments = ExcelComments.new(parent: self).parse(comments_file)
end | ruby | def parse_comments
return unless relationships
comments_target = relationships.target_by_type('comment')
return if comments_target.empty?
comments_file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/#{comments_target.first.gsub('..', '')}"
@comments = ExcelComments.new(parent: self).parse(comments_file)
end | [
"def",
"parse_comments",
"return",
"unless",
"relationships",
"comments_target",
"=",
"relationships",
".",
"target_by_type",
"(",
"'comment'",
")",
"return",
"if",
"comments_target",
".",
"empty?",
"comments_file",
"=",
"\"#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/#{comments_target.first.gsub('..', '')}\"",
"@comments",
"=",
"ExcelComments",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"comments_file",
")",
"end"
] | Do work for parsing shared comments file | [
"Do",
"work",
"for",
"parsing",
"shared",
"comments",
"file"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb#L128-L136 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/shared_string_table/string_index.rb | OoxmlParser.StringIndex.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 't'
@text = node_child.text
when 'r'
@run = ParagraphRun.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 't'
@text = node_child.text
when 'r'
@run = ParagraphRun.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'t'",
"@text",
"=",
"node_child",
".",
"text",
"when",
"'r'",
"@run",
"=",
"ParagraphRun",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse StringIndex data
@param [Nokogiri::XML:Element] node with StringIndex data
@return [StringIndex] value of StringIndex data | [
"Parse",
"StringIndex",
"data"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/shared_string_table/string_index.rb#L12-L22 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_start.rb | OoxmlParser.BookmarkStart.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'id'
@id = value.value.to_i
when 'name'
@name = value.value
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'id'
@id = value.value.to_i
when 'name'
@name = value.value
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'id'",
"@id",
"=",
"value",
".",
"value",
".",
"to_i",
"when",
"'name'",
"@name",
"=",
"value",
".",
"value",
"end",
"end",
"self",
"end"
] | Parse BookmarkStart object
@param node [Nokogiri::XML:Element] node to parse
@return [BookmarkStart] result of parsing | [
"Parse",
"BookmarkStart",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_start.rb#L12-L22 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/behavior.rb | OoxmlParser.Behavior.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'cTn'
@common_time_node = CommonTiming.new(parent: self).parse(node_child)
when 'tgtEl'
@target = TargetElement.new(parent: self).parse(node_child)
when 'attrNameLst'
node_child.xpath('p:attrName').each do |attribute_name_node|
@attribute_name_list << attribute_name_node.text
end
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'cTn'
@common_time_node = CommonTiming.new(parent: self).parse(node_child)
when 'tgtEl'
@target = TargetElement.new(parent: self).parse(node_child)
when 'attrNameLst'
node_child.xpath('p:attrName').each do |attribute_name_node|
@attribute_name_list << attribute_name_node.text
end
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'cTn'",
"@common_time_node",
"=",
"CommonTiming",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tgtEl'",
"@target",
"=",
"TargetElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'attrNameLst'",
"node_child",
".",
"xpath",
"(",
"'p:attrName'",
")",
".",
"each",
"do",
"|",
"attribute_name_node",
"|",
"@attribute_name_list",
"<<",
"attribute_name_node",
".",
"text",
"end",
"end",
"end",
"self",
"end"
] | Parse Behavior object
@param node [Nokogiri::XML:Element] node to parse
@return [Behavior] result of parsing | [
"Parse",
"Behavior",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/behavior.rb#L14-L28 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering/abstract_numbering.rb | OoxmlParser.AbstractNumbering.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'abstractNumId'
@id = value.value.to_f
end
end
node.xpath('*').each do |numbering_child_node|
case numbering_child_node.name
when 'multiLevelType'
@multilevel_type = MultilevelType.new(parent: self).parse(numbering_child_node)
when 'lvl'
@level_list << NumberingLevel.new(parent: self).parse(numbering_child_node)
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'abstractNumId'
@id = value.value.to_f
end
end
node.xpath('*').each do |numbering_child_node|
case numbering_child_node.name
when 'multiLevelType'
@multilevel_type = MultilevelType.new(parent: self).parse(numbering_child_node)
when 'lvl'
@level_list << NumberingLevel.new(parent: self).parse(numbering_child_node)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'abstractNumId'",
"@id",
"=",
"value",
".",
"value",
".",
"to_f",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"numbering_child_node",
"|",
"case",
"numbering_child_node",
".",
"name",
"when",
"'multiLevelType'",
"@multilevel_type",
"=",
"MultilevelType",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"numbering_child_node",
")",
"when",
"'lvl'",
"@level_list",
"<<",
"NumberingLevel",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"numbering_child_node",
")",
"end",
"end",
"self",
"end"
] | Parse Abstract Numbering data
@param [Nokogiri::XML:Element] node with Abstract Numbering data
@return [AbstractNumbering] value of Abstract Numbering data | [
"Parse",
"Abstract",
"Numbering",
"data"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering/abstract_numbering.rb#L23-L40 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb | OoxmlParser.XlsxRow.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'customHeight'
@custom_height = option_enabled?(node, 'customHeight')
when 'ht'
@height = OoxmlSize.new(value.value.to_f, :point)
when 'hidden'
@hidden = option_enabled?(node, 'hidden')
when 'r'
@index = value.value.to_i
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'c'
@cells[Coordinates.parse_coordinates_from_string(node_child.attribute('r').value.to_s).column_number.to_i - 1] = XlsxCell.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'customHeight'
@custom_height = option_enabled?(node, 'customHeight')
when 'ht'
@height = OoxmlSize.new(value.value.to_f, :point)
when 'hidden'
@hidden = option_enabled?(node, 'hidden')
when 'r'
@index = value.value.to_i
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'c'
@cells[Coordinates.parse_coordinates_from_string(node_child.attribute('r').value.to_s).column_number.to_i - 1] = XlsxCell.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'customHeight'",
"@custom_height",
"=",
"option_enabled?",
"(",
"node",
",",
"'customHeight'",
")",
"when",
"'ht'",
"@height",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":point",
")",
"when",
"'hidden'",
"@hidden",
"=",
"option_enabled?",
"(",
"node",
",",
"'hidden'",
")",
"when",
"'r'",
"@index",
"=",
"value",
".",
"value",
".",
"to_i",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'c'",
"@cells",
"[",
"Coordinates",
".",
"parse_coordinates_from_string",
"(",
"node_child",
".",
"attribute",
"(",
"'r'",
")",
".",
"value",
".",
"to_s",
")",
".",
"column_number",
".",
"to_i",
"-",
"1",
"]",
"=",
"XlsxCell",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse XlsxRow object
@param node [Nokogiri::XML:Element] node to parse
@return [XlsxRow] result of parsing | [
"Parse",
"XlsxRow",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb#L19-L39 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/accent.rb | OoxmlParser.Accent.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'accPr'
node_child.xpath('*').each do |node_child_child|
case node_child_child.name
when 'chr'
@symbol = node_child_child.attribute('val').value
end
end
end
end
@element = DocxFormula.new(parent: self).parse(node)
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'accPr'
node_child.xpath('*').each do |node_child_child|
case node_child_child.name
when 'chr'
@symbol = node_child_child.attribute('val').value
end
end
end
end
@element = DocxFormula.new(parent: self).parse(node)
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'accPr'",
"node_child",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child_child",
"|",
"case",
"node_child_child",
".",
"name",
"when",
"'chr'",
"@symbol",
"=",
"node_child_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"end",
"end",
"end",
"end",
"@element",
"=",
"DocxFormula",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"self",
"end"
] | Parse Accent object
@param node [Nokogiri::XML:Element] node to parse
@return [Accent] result of parsing | [
"Parse",
"Accent",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/accent.rb#L9-L23 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/color.rb | OoxmlParser.Color.looks_like? | def looks_like?(color_to_check = nil, delta = 8)
color_to_check = color_to_check.converted_color if color_to_check.is_a?(SchemeColor)
color_to_check = color_to_check.pattern_fill.foreground_folor if color_to_check.is_a?(Fill)
color_to_check = color_to_check.color.converted_color if color_to_check.is_a?(PresentationFill)
color_to_check = Color.parse(color_to_check) if color_to_check.is_a?(String)
color_to_check = Color.parse(color_to_check.to_s) if color_to_check.is_a?(Symbol)
color_to_check = Color.parse(color_to_check.value) if color_to_check.is_a?(DocxColor)
return true if none? && color_to_check.nil?
return true if none? && color_to_check.none?
return false if none? && color_to_check.any?
return false if !none? && color_to_check.none?
return true if self == color_to_check
red = color_to_check.red
green = color_to_check.green
blue = color_to_check.blue
(self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta ? true : false
end | ruby | def looks_like?(color_to_check = nil, delta = 8)
color_to_check = color_to_check.converted_color if color_to_check.is_a?(SchemeColor)
color_to_check = color_to_check.pattern_fill.foreground_folor if color_to_check.is_a?(Fill)
color_to_check = color_to_check.color.converted_color if color_to_check.is_a?(PresentationFill)
color_to_check = Color.parse(color_to_check) if color_to_check.is_a?(String)
color_to_check = Color.parse(color_to_check.to_s) if color_to_check.is_a?(Symbol)
color_to_check = Color.parse(color_to_check.value) if color_to_check.is_a?(DocxColor)
return true if none? && color_to_check.nil?
return true if none? && color_to_check.none?
return false if none? && color_to_check.any?
return false if !none? && color_to_check.none?
return true if self == color_to_check
red = color_to_check.red
green = color_to_check.green
blue = color_to_check.blue
(self.red - red).abs < delta && (self.green - green).abs < delta && (self.blue - blue).abs < delta ? true : false
end | [
"def",
"looks_like?",
"(",
"color_to_check",
"=",
"nil",
",",
"delta",
"=",
"8",
")",
"color_to_check",
"=",
"color_to_check",
".",
"converted_color",
"if",
"color_to_check",
".",
"is_a?",
"(",
"SchemeColor",
")",
"color_to_check",
"=",
"color_to_check",
".",
"pattern_fill",
".",
"foreground_folor",
"if",
"color_to_check",
".",
"is_a?",
"(",
"Fill",
")",
"color_to_check",
"=",
"color_to_check",
".",
"color",
".",
"converted_color",
"if",
"color_to_check",
".",
"is_a?",
"(",
"PresentationFill",
")",
"color_to_check",
"=",
"Color",
".",
"parse",
"(",
"color_to_check",
")",
"if",
"color_to_check",
".",
"is_a?",
"(",
"String",
")",
"color_to_check",
"=",
"Color",
".",
"parse",
"(",
"color_to_check",
".",
"to_s",
")",
"if",
"color_to_check",
".",
"is_a?",
"(",
"Symbol",
")",
"color_to_check",
"=",
"Color",
".",
"parse",
"(",
"color_to_check",
".",
"value",
")",
"if",
"color_to_check",
".",
"is_a?",
"(",
"DocxColor",
")",
"return",
"true",
"if",
"none?",
"&&",
"color_to_check",
".",
"nil?",
"return",
"true",
"if",
"none?",
"&&",
"color_to_check",
".",
"none?",
"return",
"false",
"if",
"none?",
"&&",
"color_to_check",
".",
"any?",
"return",
"false",
"if",
"!",
"none?",
"&&",
"color_to_check",
".",
"none?",
"return",
"true",
"if",
"self",
"==",
"color_to_check",
"red",
"=",
"color_to_check",
".",
"red",
"green",
"=",
"color_to_check",
".",
"green",
"blue",
"=",
"color_to_check",
".",
"blue",
"(",
"self",
".",
"red",
"-",
"red",
")",
".",
"abs",
"<",
"delta",
"&&",
"(",
"self",
".",
"green",
"-",
"green",
")",
".",
"abs",
"<",
"delta",
"&&",
"(",
"self",
".",
"blue",
"-",
"blue",
")",
".",
"abs",
"<",
"delta",
"?",
"true",
":",
"false",
"end"
] | To compare color, which look alike
@param [String or Color] color_to_check color to compare
@param [Integer] delta max delta for each of specters | [
"To",
"compare",
"color",
"which",
"look",
"alike"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/color.rb#L172-L189 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_cells_range.rb | OoxmlParser.ChartCellsRange.parse | def parse(node)
@list = node.xpath('c:f')[0].text.split('!').first
coordinates = Coordinates.parser_coordinates_range(node.xpath('c:f')[0].text) # .split('!')[1].gsub('$', ''))
return self unless coordinates
node.xpath('c:numCache/c:pt').each_with_index do |point_node, index|
point = ChartPoint.new(coordinates[index])
point.value = point_node.xpath('c:v').first.text.to_f unless point_node.xpath('c:v').first.nil?
@points << point
end
self
end | ruby | def parse(node)
@list = node.xpath('c:f')[0].text.split('!').first
coordinates = Coordinates.parser_coordinates_range(node.xpath('c:f')[0].text) # .split('!')[1].gsub('$', ''))
return self unless coordinates
node.xpath('c:numCache/c:pt').each_with_index do |point_node, index|
point = ChartPoint.new(coordinates[index])
point.value = point_node.xpath('c:v').first.text.to_f unless point_node.xpath('c:v').first.nil?
@points << point
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"@list",
"=",
"node",
".",
"xpath",
"(",
"'c:f'",
")",
"[",
"0",
"]",
".",
"text",
".",
"split",
"(",
"'!'",
")",
".",
"first",
"coordinates",
"=",
"Coordinates",
".",
"parser_coordinates_range",
"(",
"node",
".",
"xpath",
"(",
"'c:f'",
")",
"[",
"0",
"]",
".",
"text",
")",
"# .split('!')[1].gsub('$', ''))",
"return",
"self",
"unless",
"coordinates",
"node",
".",
"xpath",
"(",
"'c:numCache/c:pt'",
")",
".",
"each_with_index",
"do",
"|",
"point_node",
",",
"index",
"|",
"point",
"=",
"ChartPoint",
".",
"new",
"(",
"coordinates",
"[",
"index",
"]",
")",
"point",
".",
"value",
"=",
"point_node",
".",
"xpath",
"(",
"'c:v'",
")",
".",
"first",
".",
"text",
".",
"to_f",
"unless",
"point_node",
".",
"xpath",
"(",
"'c:v'",
")",
".",
"first",
".",
"nil?",
"@points",
"<<",
"point",
"end",
"self",
"end"
] | Parse ChartCellsRange object
@param node [Nokogiri::XML:Element] node to parse
@return [ChartCellsRange] result of parsing | [
"Parse",
"ChartCellsRange",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_cells_range.rb#L15-L26 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/cell_style/alignment.rb | OoxmlParser.XlsxAlignment.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'horizontal'
@horizontal = value.value.to_sym
@wrap_text = true if @horizontal == :justify
when 'vertical'
@vertical = value.value.to_sym
when 'wrapText'
@wrap_text = value.value.to_s == '1'
when 'textRotation'
@text_rotation = value.value.to_i
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'horizontal'
@horizontal = value.value.to_sym
@wrap_text = true if @horizontal == :justify
when 'vertical'
@vertical = value.value.to_sym
when 'wrapText'
@wrap_text = value.value.to_s == '1'
when 'textRotation'
@text_rotation = value.value.to_i
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'horizontal'",
"@horizontal",
"=",
"value",
".",
"value",
".",
"to_sym",
"@wrap_text",
"=",
"true",
"if",
"@horizontal",
"==",
":justify",
"when",
"'vertical'",
"@vertical",
"=",
"value",
".",
"value",
".",
"to_sym",
"when",
"'wrapText'",
"@wrap_text",
"=",
"value",
".",
"value",
".",
"to_s",
"==",
"'1'",
"when",
"'textRotation'",
"@text_rotation",
"=",
"value",
".",
"value",
".",
"to_i",
"end",
"end",
"self",
"end"
] | Parse XlsxAlignment object
@param node [Nokogiri::XML:Element] node to parse
@return [XlsxAlignment] result of parsing | [
"Parse",
"XlsxAlignment",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/cell_style/alignment.rb#L16-L31 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb | OoxmlParser.TableStyle.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'styleId'
@id = value.value.to_s
when 'styleName'
@name = value.value.to_s
when 'val'
@value = value.value.to_s
end
end
node.xpath('*').each do |style_node_child|
case style_node_child.name
when 'wholeTbl'
@whole_table = TableElement.new(parent: self).parse(style_node_child)
when 'band1H'
@banding_1_horizontal = TableElement.new(parent: self).parse(style_node_child)
when 'band2H', 'band2Horz'
@banding_2_horizontal = TableElement.new(parent: self).parse(style_node_child)
when 'band1V'
@banding_1_vertical = TableElement.new(parent: self).parse(style_node_child)
when 'band2V'
@banding_2_vertical = TableElement.new(parent: self).parse(style_node_child)
when 'lastCol'
@last_column = TableElement.new(parent: self).parse(style_node_child)
when 'firstCol'
@first_column = TableElement.new(parent: self).parse(style_node_child)
when 'lastRow'
@last_row = TableElement.new(parent: self).parse(style_node_child)
when 'firstRow'
@first_row = TableElement.new(parent: self).parse(style_node_child)
when 'seCell'
@southeast_cell = TableElement.new(parent: self).parse(style_node_child)
when 'swCell'
@southwest_cell = TableElement.new(parent: self).parse(style_node_child)
when 'neCell'
@northeast_cell = TableElement.new(parent: self).parse(style_node_child)
when 'nwCell'
@northwest_cell = TableElement.new(parent: self).parse(style_node_child)
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'styleId'
@id = value.value.to_s
when 'styleName'
@name = value.value.to_s
when 'val'
@value = value.value.to_s
end
end
node.xpath('*').each do |style_node_child|
case style_node_child.name
when 'wholeTbl'
@whole_table = TableElement.new(parent: self).parse(style_node_child)
when 'band1H'
@banding_1_horizontal = TableElement.new(parent: self).parse(style_node_child)
when 'band2H', 'band2Horz'
@banding_2_horizontal = TableElement.new(parent: self).parse(style_node_child)
when 'band1V'
@banding_1_vertical = TableElement.new(parent: self).parse(style_node_child)
when 'band2V'
@banding_2_vertical = TableElement.new(parent: self).parse(style_node_child)
when 'lastCol'
@last_column = TableElement.new(parent: self).parse(style_node_child)
when 'firstCol'
@first_column = TableElement.new(parent: self).parse(style_node_child)
when 'lastRow'
@last_row = TableElement.new(parent: self).parse(style_node_child)
when 'firstRow'
@first_row = TableElement.new(parent: self).parse(style_node_child)
when 'seCell'
@southeast_cell = TableElement.new(parent: self).parse(style_node_child)
when 'swCell'
@southwest_cell = TableElement.new(parent: self).parse(style_node_child)
when 'neCell'
@northeast_cell = TableElement.new(parent: self).parse(style_node_child)
when 'nwCell'
@northwest_cell = TableElement.new(parent: self).parse(style_node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'styleId'",
"@id",
"=",
"value",
".",
"value",
".",
"to_s",
"when",
"'styleName'",
"@name",
"=",
"value",
".",
"value",
".",
"to_s",
"when",
"'val'",
"@value",
"=",
"value",
".",
"value",
".",
"to_s",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"style_node_child",
"|",
"case",
"style_node_child",
".",
"name",
"when",
"'wholeTbl'",
"@whole_table",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'band1H'",
"@banding_1_horizontal",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'band2H'",
",",
"'band2Horz'",
"@banding_2_horizontal",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'band1V'",
"@banding_1_vertical",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'band2V'",
"@banding_2_vertical",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'lastCol'",
"@last_column",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'firstCol'",
"@first_column",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'lastRow'",
"@last_row",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'firstRow'",
"@first_row",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'seCell'",
"@southeast_cell",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'swCell'",
"@southwest_cell",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'neCell'",
"@northeast_cell",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"when",
"'nwCell'",
"@northwest_cell",
"=",
"TableElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"style_node_child",
")",
"end",
"end",
"self",
"end"
] | Parse TableStyle object
@param node [Nokogiri::XML:Element] node to parse
@return [TableStyle] result of parsing | [
"Parse",
"TableStyle",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb#L14-L57 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb | OoxmlParser.ParagraphRun.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'rPr'
@properties = RunProperties.new(parent: self).parse(node_child)
when 't'
@t = Text.new(parent: self).parse(node_child)
@text = t.text
when 'tab'
@tab = Tab.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'rPr'
@properties = RunProperties.new(parent: self).parse(node_child)
when 't'
@t = Text.new(parent: self).parse(node_child)
@text = t.text
when 'tab'
@tab = Tab.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'rPr'",
"@properties",
"=",
"RunProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'t'",
"@t",
"=",
"Text",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"@text",
"=",
"t",
".",
"text",
"when",
"'tab'",
"@tab",
"=",
"Tab",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse ParagraphRun object
@param node [Nokogiri::XML:Element] node to parse
@return [ParagraphRun] result of parsing | [
"Parse",
"ParagraphRun",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb#L21-L34 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb | OoxmlParser.XLSXWorkbook.all_formula_values | def all_formula_values(precision = 14)
formulas = []
worksheets.each do |c_sheet|
next unless c_sheet
c_sheet.rows.each do |c_row|
next unless c_row
c_row.cells.each do |c_cell|
next unless c_cell
next unless c_cell.formula
next if c_cell.formula.empty?
text = c_cell.raw_text
if StringHelper.numeric?(text)
text = text.to_f.round(10).to_s[0..precision]
elsif StringHelper.complex?(text)
complex_number = Complex(text.tr(',', '.'))
real_part = complex_number.real
real_rounded = real_part.to_f.round(10).to_s[0..precision].to_f
imag_part = complex_number.imag
imag_rounded = imag_part.to_f.round(10).to_s[0..precision].to_f
complex_rounded = Complex(real_rounded, imag_rounded)
text = complex_rounded.to_s
end
formulas << text
end
end
end
formulas
end | ruby | def all_formula_values(precision = 14)
formulas = []
worksheets.each do |c_sheet|
next unless c_sheet
c_sheet.rows.each do |c_row|
next unless c_row
c_row.cells.each do |c_cell|
next unless c_cell
next unless c_cell.formula
next if c_cell.formula.empty?
text = c_cell.raw_text
if StringHelper.numeric?(text)
text = text.to_f.round(10).to_s[0..precision]
elsif StringHelper.complex?(text)
complex_number = Complex(text.tr(',', '.'))
real_part = complex_number.real
real_rounded = real_part.to_f.round(10).to_s[0..precision].to_f
imag_part = complex_number.imag
imag_rounded = imag_part.to_f.round(10).to_s[0..precision].to_f
complex_rounded = Complex(real_rounded, imag_rounded)
text = complex_rounded.to_s
end
formulas << text
end
end
end
formulas
end | [
"def",
"all_formula_values",
"(",
"precision",
"=",
"14",
")",
"formulas",
"=",
"[",
"]",
"worksheets",
".",
"each",
"do",
"|",
"c_sheet",
"|",
"next",
"unless",
"c_sheet",
"c_sheet",
".",
"rows",
".",
"each",
"do",
"|",
"c_row",
"|",
"next",
"unless",
"c_row",
"c_row",
".",
"cells",
".",
"each",
"do",
"|",
"c_cell",
"|",
"next",
"unless",
"c_cell",
"next",
"unless",
"c_cell",
".",
"formula",
"next",
"if",
"c_cell",
".",
"formula",
".",
"empty?",
"text",
"=",
"c_cell",
".",
"raw_text",
"if",
"StringHelper",
".",
"numeric?",
"(",
"text",
")",
"text",
"=",
"text",
".",
"to_f",
".",
"round",
"(",
"10",
")",
".",
"to_s",
"[",
"0",
"..",
"precision",
"]",
"elsif",
"StringHelper",
".",
"complex?",
"(",
"text",
")",
"complex_number",
"=",
"Complex",
"(",
"text",
".",
"tr",
"(",
"','",
",",
"'.'",
")",
")",
"real_part",
"=",
"complex_number",
".",
"real",
"real_rounded",
"=",
"real_part",
".",
"to_f",
".",
"round",
"(",
"10",
")",
".",
"to_s",
"[",
"0",
"..",
"precision",
"]",
".",
"to_f",
"imag_part",
"=",
"complex_number",
".",
"imag",
"imag_rounded",
"=",
"imag_part",
".",
"to_f",
".",
"round",
"(",
"10",
")",
".",
"to_s",
"[",
"0",
"..",
"precision",
"]",
".",
"to_f",
"complex_rounded",
"=",
"Complex",
"(",
"real_rounded",
",",
"imag_rounded",
")",
"text",
"=",
"complex_rounded",
".",
"to_s",
"end",
"formulas",
"<<",
"text",
"end",
"end",
"end",
"formulas",
"end"
] | Get all values of formulas.
@param [Fixnum] precision of formulas counting
@return [Array, String] all formulas | [
"Get",
"all",
"values",
"of",
"formulas",
"."
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb#L51-L82 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb | OoxmlParser.XLSXWorkbook.parse_shared_strings | def parse_shared_strings
shared_strings_target = relationships.target_by_type('sharedString')
return if shared_strings_target.empty?
shared_string_file = "#{OOXMLDocumentObject.path_to_folder}/xl/#{shared_strings_target.first}"
@shared_strings_table = SharedStringTable.new(parent: self).parse(shared_string_file)
end | ruby | def parse_shared_strings
shared_strings_target = relationships.target_by_type('sharedString')
return if shared_strings_target.empty?
shared_string_file = "#{OOXMLDocumentObject.path_to_folder}/xl/#{shared_strings_target.first}"
@shared_strings_table = SharedStringTable.new(parent: self).parse(shared_string_file)
end | [
"def",
"parse_shared_strings",
"shared_strings_target",
"=",
"relationships",
".",
"target_by_type",
"(",
"'sharedString'",
")",
"return",
"if",
"shared_strings_target",
".",
"empty?",
"shared_string_file",
"=",
"\"#{OOXMLDocumentObject.path_to_folder}/xl/#{shared_strings_target.first}\"",
"@shared_strings_table",
"=",
"SharedStringTable",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"shared_string_file",
")",
"end"
] | Do work for parsing shared strings file | [
"Do",
"work",
"for",
"parsing",
"shared",
"strings",
"file"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb#L85-L91 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb | OoxmlParser.TablePosition.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'leftFromText'
@left = OoxmlSize.new(value.value.to_f)
when 'rightFromText'
@right = OoxmlSize.new(value.value.to_f)
when 'topFromText'
@top = OoxmlSize.new(value.value.to_f)
when 'bottomFromText'
@bottom = OoxmlSize.new(value.value.to_f)
when 'tblpX'
@position_x = OoxmlSize.new(value.value.to_f)
when 'tblpY'
@position_y = OoxmlSize.new(value.value.to_f)
when 'vertAnchor'
@vertical_anchor = value.value.to_sym
when 'horzAnchor'
@horizontal_anchor = value.value.to_sym
when 'tblpXSpec'
@horizontal_align_from_anchor = value.value.to_sym
when 'tblpYSpec'
@vertical_align_from_anchor = value.value.to_sym
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'leftFromText'
@left = OoxmlSize.new(value.value.to_f)
when 'rightFromText'
@right = OoxmlSize.new(value.value.to_f)
when 'topFromText'
@top = OoxmlSize.new(value.value.to_f)
when 'bottomFromText'
@bottom = OoxmlSize.new(value.value.to_f)
when 'tblpX'
@position_x = OoxmlSize.new(value.value.to_f)
when 'tblpY'
@position_y = OoxmlSize.new(value.value.to_f)
when 'vertAnchor'
@vertical_anchor = value.value.to_sym
when 'horzAnchor'
@horizontal_anchor = value.value.to_sym
when 'tblpXSpec'
@horizontal_align_from_anchor = value.value.to_sym
when 'tblpYSpec'
@vertical_align_from_anchor = value.value.to_sym
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'leftFromText'",
"@left",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
")",
"when",
"'rightFromText'",
"@right",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
")",
"when",
"'topFromText'",
"@top",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
")",
"when",
"'bottomFromText'",
"@bottom",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
")",
"when",
"'tblpX'",
"@position_x",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
")",
"when",
"'tblpY'",
"@position_y",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
")",
"when",
"'vertAnchor'",
"@vertical_anchor",
"=",
"value",
".",
"value",
".",
"to_sym",
"when",
"'horzAnchor'",
"@horizontal_anchor",
"=",
"value",
".",
"value",
".",
"to_sym",
"when",
"'tblpXSpec'",
"@horizontal_align_from_anchor",
"=",
"value",
".",
"value",
".",
"to_sym",
"when",
"'tblpYSpec'",
"@vertical_align_from_anchor",
"=",
"value",
".",
"value",
".",
"to_sym",
"end",
"end",
"self",
"end"
] | Parse TablePosition object
@param node [Nokogiri::XML:Element] node to parse
@return [TablePosition] result of parsing | [
"Parse",
"TablePosition",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb#L14-L40 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb | OoxmlParser.Shape.parse | def parse(node, type)
@type = type
node.attribute('style').value.to_s.split(';').each do |property|
if property.include?('margin-top')
@properties.margins.top = property.split(':').last
elsif property.include?('margin-left')
@properties.margins.left = property.split(':').last
elsif property.include?('margin-right')
@properties.margins.right = property.split(':').last
elsif property.include?('width')
@properties.size.width = property.split(':').last
elsif property.include?('height')
@properties.size.height = property.split(':').last
elsif property.include?('z-index')
@properties.z_index = property.split(':').last
elsif property.include?('position')
@properties.position = property.split(':').last
end
end
@properties.fill_color = Color.new(parent: self).parse_hex_string(node.attribute('fillcolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('fillcolor').nil?
@properties.stroke.weight = node.attribute('strokeweight').value unless node.attribute('strokeweight').nil?
@properties.stroke.color = Color.new(parent: self).parse_hex_string(node.attribute('strokecolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('strokecolor').nil?
@elements = TextBox.parse_list(node.xpath('v:textbox').first, parent: self) unless node.xpath('v:textbox').first.nil?
self
end | ruby | def parse(node, type)
@type = type
node.attribute('style').value.to_s.split(';').each do |property|
if property.include?('margin-top')
@properties.margins.top = property.split(':').last
elsif property.include?('margin-left')
@properties.margins.left = property.split(':').last
elsif property.include?('margin-right')
@properties.margins.right = property.split(':').last
elsif property.include?('width')
@properties.size.width = property.split(':').last
elsif property.include?('height')
@properties.size.height = property.split(':').last
elsif property.include?('z-index')
@properties.z_index = property.split(':').last
elsif property.include?('position')
@properties.position = property.split(':').last
end
end
@properties.fill_color = Color.new(parent: self).parse_hex_string(node.attribute('fillcolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('fillcolor').nil?
@properties.stroke.weight = node.attribute('strokeweight').value unless node.attribute('strokeweight').nil?
@properties.stroke.color = Color.new(parent: self).parse_hex_string(node.attribute('strokecolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('strokecolor').nil?
@elements = TextBox.parse_list(node.xpath('v:textbox').first, parent: self) unless node.xpath('v:textbox').first.nil?
self
end | [
"def",
"parse",
"(",
"node",
",",
"type",
")",
"@type",
"=",
"type",
"node",
".",
"attribute",
"(",
"'style'",
")",
".",
"value",
".",
"to_s",
".",
"split",
"(",
"';'",
")",
".",
"each",
"do",
"|",
"property",
"|",
"if",
"property",
".",
"include?",
"(",
"'margin-top'",
")",
"@properties",
".",
"margins",
".",
"top",
"=",
"property",
".",
"split",
"(",
"':'",
")",
".",
"last",
"elsif",
"property",
".",
"include?",
"(",
"'margin-left'",
")",
"@properties",
".",
"margins",
".",
"left",
"=",
"property",
".",
"split",
"(",
"':'",
")",
".",
"last",
"elsif",
"property",
".",
"include?",
"(",
"'margin-right'",
")",
"@properties",
".",
"margins",
".",
"right",
"=",
"property",
".",
"split",
"(",
"':'",
")",
".",
"last",
"elsif",
"property",
".",
"include?",
"(",
"'width'",
")",
"@properties",
".",
"size",
".",
"width",
"=",
"property",
".",
"split",
"(",
"':'",
")",
".",
"last",
"elsif",
"property",
".",
"include?",
"(",
"'height'",
")",
"@properties",
".",
"size",
".",
"height",
"=",
"property",
".",
"split",
"(",
"':'",
")",
".",
"last",
"elsif",
"property",
".",
"include?",
"(",
"'z-index'",
")",
"@properties",
".",
"z_index",
"=",
"property",
".",
"split",
"(",
"':'",
")",
".",
"last",
"elsif",
"property",
".",
"include?",
"(",
"'position'",
")",
"@properties",
".",
"position",
"=",
"property",
".",
"split",
"(",
"':'",
")",
".",
"last",
"end",
"end",
"@properties",
".",
"fill_color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_hex_string",
"(",
"node",
".",
"attribute",
"(",
"'fillcolor'",
")",
".",
"value",
".",
"to_s",
".",
"sub",
"(",
"'#'",
",",
"''",
")",
".",
"split",
"(",
"' '",
")",
".",
"first",
")",
"unless",
"node",
".",
"attribute",
"(",
"'fillcolor'",
")",
".",
"nil?",
"@properties",
".",
"stroke",
".",
"weight",
"=",
"node",
".",
"attribute",
"(",
"'strokeweight'",
")",
".",
"value",
"unless",
"node",
".",
"attribute",
"(",
"'strokeweight'",
")",
".",
"nil?",
"@properties",
".",
"stroke",
".",
"color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_hex_string",
"(",
"node",
".",
"attribute",
"(",
"'strokecolor'",
")",
".",
"value",
".",
"to_s",
".",
"sub",
"(",
"'#'",
",",
"''",
")",
".",
"split",
"(",
"' '",
")",
".",
"first",
")",
"unless",
"node",
".",
"attribute",
"(",
"'strokecolor'",
")",
".",
"nil?",
"@elements",
"=",
"TextBox",
".",
"parse_list",
"(",
"node",
".",
"xpath",
"(",
"'v:textbox'",
")",
".",
"first",
",",
"parent",
":",
"self",
")",
"unless",
"node",
".",
"xpath",
"(",
"'v:textbox'",
")",
".",
"first",
".",
"nil?",
"self",
"end"
] | Parse Shape object
@param node [Nokogiri::XML:Element] node to parse
@return [Shape] result of parsing | [
"Parse",
"Shape",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb#L20-L44 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/paragraph/text_field.rb | OoxmlParser.TextField.parse | def parse(node)
@id = node.attribute('id').value
@type = node.attribute('type').value
node.xpath('*').each do |text_field_node_child|
case text_field_node_child.name
when 't'
@text = text_field_node_child.text
end
end
self
end | ruby | def parse(node)
@id = node.attribute('id').value
@type = node.attribute('type').value
node.xpath('*').each do |text_field_node_child|
case text_field_node_child.name
when 't'
@text = text_field_node_child.text
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"@id",
"=",
"node",
".",
"attribute",
"(",
"'id'",
")",
".",
"value",
"@type",
"=",
"node",
".",
"attribute",
"(",
"'type'",
")",
".",
"value",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"text_field_node_child",
"|",
"case",
"text_field_node_child",
".",
"name",
"when",
"'t'",
"@text",
"=",
"text_field_node_child",
".",
"text",
"end",
"end",
"self",
"end"
] | Parse TextField object
@param node [Nokogiri::XML:Element] node to parse
@return [TextField] result of parsing | [
"Parse",
"TextField",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/paragraph/text_field.rb#L9-L19 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb | OoxmlParser.DocxColor.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blipFill'
@type = :picture
@value = DocxBlip.new(parent: self).parse(node_child)
node_child.xpath('*').each do |fill_type_node_child|
case fill_type_node_child.name
when 'tile'
@stretching_type = :tile
when 'stretch'
@stretching_type = :stretch
when 'blip'
fill_type_node_child.xpath('alphaModFix').each { |alpha_node| @alpha = alpha_node.attribute('amt').value.to_i / 1_000.0 }
end
end
when 'solidFill'
@type = :solid
@value = Color.new(parent: self).parse_color_model(node_child)
when 'gradFill'
@type = :gradient
@value = GradientColor.new(parent: self).parse(node_child)
when 'pattFill'
@type = :pattern
@value = DocxPatternFill.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blipFill'
@type = :picture
@value = DocxBlip.new(parent: self).parse(node_child)
node_child.xpath('*').each do |fill_type_node_child|
case fill_type_node_child.name
when 'tile'
@stretching_type = :tile
when 'stretch'
@stretching_type = :stretch
when 'blip'
fill_type_node_child.xpath('alphaModFix').each { |alpha_node| @alpha = alpha_node.attribute('amt').value.to_i / 1_000.0 }
end
end
when 'solidFill'
@type = :solid
@value = Color.new(parent: self).parse_color_model(node_child)
when 'gradFill'
@type = :gradient
@value = GradientColor.new(parent: self).parse(node_child)
when 'pattFill'
@type = :pattern
@value = DocxPatternFill.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'blipFill'",
"@type",
"=",
":picture",
"@value",
"=",
"DocxBlip",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"node_child",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"fill_type_node_child",
"|",
"case",
"fill_type_node_child",
".",
"name",
"when",
"'tile'",
"@stretching_type",
"=",
":tile",
"when",
"'stretch'",
"@stretching_type",
"=",
":stretch",
"when",
"'blip'",
"fill_type_node_child",
".",
"xpath",
"(",
"'alphaModFix'",
")",
".",
"each",
"{",
"|",
"alpha_node",
"|",
"@alpha",
"=",
"alpha_node",
".",
"attribute",
"(",
"'amt'",
")",
".",
"value",
".",
"to_i",
"/",
"1_000.0",
"}",
"end",
"end",
"when",
"'solidFill'",
"@type",
"=",
":solid",
"@value",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color_model",
"(",
"node_child",
")",
"when",
"'gradFill'",
"@type",
"=",
":gradient",
"@value",
"=",
"GradientColor",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'pattFill'",
"@type",
"=",
":pattern",
"@value",
"=",
"DocxPatternFill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse DocxColor object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxColor] result of parsing | [
"Parse",
"DocxColor",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_color.rb#L10-L38 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb | OoxmlParser.PageProperties.parse | def parse(node, default_paragraph, default_character)
node.xpath('*').each do |pg_size_subnode|
case pg_size_subnode.name
when 'pgSz'
@size = PageSize.new.parse(pg_size_subnode)
when 'pgBorders'
page_borders = Borders.new
page_borders.display = pg_size_subnode.attribute('display').value.to_sym unless pg_size_subnode.attribute('display').nil?
page_borders.offset_from = pg_size_subnode.attribute('offsetFrom').value.to_sym unless pg_size_subnode.attribute('offsetFrom').nil?
pg_size_subnode.xpath('w:bottom').each do |bottom|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(bottom)
end
pg_size_subnode.xpath('w:left').each do |left|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(left)
end
pg_size_subnode.xpath('w:top').each do |top|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(top)
end
pg_size_subnode.xpath('w:right').each do |right|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(right)
end
@page_borders = page_borders
when 'type'
@type = pg_size_subnode.attribute('val').value
when 'pgMar'
@margins = PageMargins.new(parent: self).parse(pg_size_subnode)
when 'pgNumType'
@num_type = pg_size_subnode.attribute('fmt').value unless pg_size_subnode.attribute('fmt').nil?
when 'formProt'
@form_prot = pg_size_subnode.attribute('val').value
when 'textDirection'
@text_direction = pg_size_subnode.attribute('val').value
when 'docGrid'
@document_grid = DocumentGrid.new(parent: self).parse(pg_size_subnode)
when 'titlePg'
@title_page = option_enabled?(pg_size_subnode)
when 'cols'
@columns = Columns.new.parse(pg_size_subnode)
when 'headerReference', 'footerReference'
target = OOXMLDocumentObject.get_link_from_rels(pg_size_subnode.attribute('id').value)
OOXMLDocumentObject.add_to_xmls_stack("word/#{target}")
note = Note.parse(default_paragraph: default_paragraph,
default_character: default_character,
target: target,
assigned_to: pg_size_subnode.attribute('type').value,
type: File.basename(target).sub('.xml', ''),
parent: self)
@notes << note
OOXMLDocumentObject.xmls_stack.pop
when 'footnotePr'
@footnote_properties = FootnoteProperties.new(parent: self).parse(pg_size_subnode)
end
end
self
end | ruby | def parse(node, default_paragraph, default_character)
node.xpath('*').each do |pg_size_subnode|
case pg_size_subnode.name
when 'pgSz'
@size = PageSize.new.parse(pg_size_subnode)
when 'pgBorders'
page_borders = Borders.new
page_borders.display = pg_size_subnode.attribute('display').value.to_sym unless pg_size_subnode.attribute('display').nil?
page_borders.offset_from = pg_size_subnode.attribute('offsetFrom').value.to_sym unless pg_size_subnode.attribute('offsetFrom').nil?
pg_size_subnode.xpath('w:bottom').each do |bottom|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(bottom)
end
pg_size_subnode.xpath('w:left').each do |left|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(left)
end
pg_size_subnode.xpath('w:top').each do |top|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(top)
end
pg_size_subnode.xpath('w:right').each do |right|
page_borders.bottom = BordersProperties.new(parent: page_borders).parse(right)
end
@page_borders = page_borders
when 'type'
@type = pg_size_subnode.attribute('val').value
when 'pgMar'
@margins = PageMargins.new(parent: self).parse(pg_size_subnode)
when 'pgNumType'
@num_type = pg_size_subnode.attribute('fmt').value unless pg_size_subnode.attribute('fmt').nil?
when 'formProt'
@form_prot = pg_size_subnode.attribute('val').value
when 'textDirection'
@text_direction = pg_size_subnode.attribute('val').value
when 'docGrid'
@document_grid = DocumentGrid.new(parent: self).parse(pg_size_subnode)
when 'titlePg'
@title_page = option_enabled?(pg_size_subnode)
when 'cols'
@columns = Columns.new.parse(pg_size_subnode)
when 'headerReference', 'footerReference'
target = OOXMLDocumentObject.get_link_from_rels(pg_size_subnode.attribute('id').value)
OOXMLDocumentObject.add_to_xmls_stack("word/#{target}")
note = Note.parse(default_paragraph: default_paragraph,
default_character: default_character,
target: target,
assigned_to: pg_size_subnode.attribute('type').value,
type: File.basename(target).sub('.xml', ''),
parent: self)
@notes << note
OOXMLDocumentObject.xmls_stack.pop
when 'footnotePr'
@footnote_properties = FootnoteProperties.new(parent: self).parse(pg_size_subnode)
end
end
self
end | [
"def",
"parse",
"(",
"node",
",",
"default_paragraph",
",",
"default_character",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"pg_size_subnode",
"|",
"case",
"pg_size_subnode",
".",
"name",
"when",
"'pgSz'",
"@size",
"=",
"PageSize",
".",
"new",
".",
"parse",
"(",
"pg_size_subnode",
")",
"when",
"'pgBorders'",
"page_borders",
"=",
"Borders",
".",
"new",
"page_borders",
".",
"display",
"=",
"pg_size_subnode",
".",
"attribute",
"(",
"'display'",
")",
".",
"value",
".",
"to_sym",
"unless",
"pg_size_subnode",
".",
"attribute",
"(",
"'display'",
")",
".",
"nil?",
"page_borders",
".",
"offset_from",
"=",
"pg_size_subnode",
".",
"attribute",
"(",
"'offsetFrom'",
")",
".",
"value",
".",
"to_sym",
"unless",
"pg_size_subnode",
".",
"attribute",
"(",
"'offsetFrom'",
")",
".",
"nil?",
"pg_size_subnode",
".",
"xpath",
"(",
"'w:bottom'",
")",
".",
"each",
"do",
"|",
"bottom",
"|",
"page_borders",
".",
"bottom",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"page_borders",
")",
".",
"parse",
"(",
"bottom",
")",
"end",
"pg_size_subnode",
".",
"xpath",
"(",
"'w:left'",
")",
".",
"each",
"do",
"|",
"left",
"|",
"page_borders",
".",
"bottom",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"page_borders",
")",
".",
"parse",
"(",
"left",
")",
"end",
"pg_size_subnode",
".",
"xpath",
"(",
"'w:top'",
")",
".",
"each",
"do",
"|",
"top",
"|",
"page_borders",
".",
"bottom",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"page_borders",
")",
".",
"parse",
"(",
"top",
")",
"end",
"pg_size_subnode",
".",
"xpath",
"(",
"'w:right'",
")",
".",
"each",
"do",
"|",
"right",
"|",
"page_borders",
".",
"bottom",
"=",
"BordersProperties",
".",
"new",
"(",
"parent",
":",
"page_borders",
")",
".",
"parse",
"(",
"right",
")",
"end",
"@page_borders",
"=",
"page_borders",
"when",
"'type'",
"@type",
"=",
"pg_size_subnode",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'pgMar'",
"@margins",
"=",
"PageMargins",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"pg_size_subnode",
")",
"when",
"'pgNumType'",
"@num_type",
"=",
"pg_size_subnode",
".",
"attribute",
"(",
"'fmt'",
")",
".",
"value",
"unless",
"pg_size_subnode",
".",
"attribute",
"(",
"'fmt'",
")",
".",
"nil?",
"when",
"'formProt'",
"@form_prot",
"=",
"pg_size_subnode",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'textDirection'",
"@text_direction",
"=",
"pg_size_subnode",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'docGrid'",
"@document_grid",
"=",
"DocumentGrid",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"pg_size_subnode",
")",
"when",
"'titlePg'",
"@title_page",
"=",
"option_enabled?",
"(",
"pg_size_subnode",
")",
"when",
"'cols'",
"@columns",
"=",
"Columns",
".",
"new",
".",
"parse",
"(",
"pg_size_subnode",
")",
"when",
"'headerReference'",
",",
"'footerReference'",
"target",
"=",
"OOXMLDocumentObject",
".",
"get_link_from_rels",
"(",
"pg_size_subnode",
".",
"attribute",
"(",
"'id'",
")",
".",
"value",
")",
"OOXMLDocumentObject",
".",
"add_to_xmls_stack",
"(",
"\"word/#{target}\"",
")",
"note",
"=",
"Note",
".",
"parse",
"(",
"default_paragraph",
":",
"default_paragraph",
",",
"default_character",
":",
"default_character",
",",
"target",
":",
"target",
",",
"assigned_to",
":",
"pg_size_subnode",
".",
"attribute",
"(",
"'type'",
")",
".",
"value",
",",
"type",
":",
"File",
".",
"basename",
"(",
"target",
")",
".",
"sub",
"(",
"'.xml'",
",",
"''",
")",
",",
"parent",
":",
"self",
")",
"@notes",
"<<",
"note",
"OOXMLDocumentObject",
".",
"xmls_stack",
".",
"pop",
"when",
"'footnotePr'",
"@footnote_properties",
"=",
"FootnoteProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"pg_size_subnode",
")",
"end",
"end",
"self",
"end"
] | Parse PageProperties data
@param [Nokogiri::XML:Element] node with PageProperties data
@return [PageProperties] value of PageProperties data | [
"Parse",
"PageProperties",
"data"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb#L24-L78 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis_title.rb | OoxmlParser.ChartAxisTitle.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'tx'
node_child.xpath('c:rich/*').each do |rich_node_child|
case rich_node_child.name
when 'p'
root_object.default_font_style = FontStyle.new(true) # Default font style for chart title always bold
@elements << Paragraph.new(parent: self).parse(rich_node_child)
root_object.default_font_style = FontStyle.new
end
end
when 'layout'
@layout = option_enabled?(node_child)
when 'overlay'
@overlay = option_enabled?(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'tx'
node_child.xpath('c:rich/*').each do |rich_node_child|
case rich_node_child.name
when 'p'
root_object.default_font_style = FontStyle.new(true) # Default font style for chart title always bold
@elements << Paragraph.new(parent: self).parse(rich_node_child)
root_object.default_font_style = FontStyle.new
end
end
when 'layout'
@layout = option_enabled?(node_child)
when 'overlay'
@overlay = option_enabled?(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'tx'",
"node_child",
".",
"xpath",
"(",
"'c:rich/*'",
")",
".",
"each",
"do",
"|",
"rich_node_child",
"|",
"case",
"rich_node_child",
".",
"name",
"when",
"'p'",
"root_object",
".",
"default_font_style",
"=",
"FontStyle",
".",
"new",
"(",
"true",
")",
"# Default font style for chart title always bold",
"@elements",
"<<",
"Paragraph",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"rich_node_child",
")",
"root_object",
".",
"default_font_style",
"=",
"FontStyle",
".",
"new",
"end",
"end",
"when",
"'layout'",
"@layout",
"=",
"option_enabled?",
"(",
"node_child",
")",
"when",
"'overlay'",
"@overlay",
"=",
"option_enabled?",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse ChartAxisTitle object
@param node [Nokogiri::XML:Element] node to parse
@return [ChartAxisTitle] result of parsing | [
"Parse",
"ChartAxisTitle",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart_axis_title.rb#L19-L38 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb | OoxmlParser.XlsxDrawing.parse | def parse(node)
node.xpath('*').each do |child_node|
case child_node.name
when 'from'
@from = XlsxDrawingPositionParameters.new(parent: self).parse(child_node)
when 'to'
@to = XlsxDrawingPositionParameters.new(parent: self).parse(child_node)
when 'sp'
@shape = DocxShape.new(parent: self).parse(child_node)
when 'grpSp'
@grouping = ShapesGrouping.new(parent: self).parse(child_node)
when 'pic'
@picture = DocxPicture.new(parent: self).parse(child_node)
when 'graphicFrame'
@graphic_frame = GraphicFrame.new(parent: self).parse(child_node)
when 'cxnSp'
@shape = ConnectionShape.new(parent: self).parse(child_node)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |child_node|
case child_node.name
when 'from'
@from = XlsxDrawingPositionParameters.new(parent: self).parse(child_node)
when 'to'
@to = XlsxDrawingPositionParameters.new(parent: self).parse(child_node)
when 'sp'
@shape = DocxShape.new(parent: self).parse(child_node)
when 'grpSp'
@grouping = ShapesGrouping.new(parent: self).parse(child_node)
when 'pic'
@picture = DocxPicture.new(parent: self).parse(child_node)
when 'graphicFrame'
@graphic_frame = GraphicFrame.new(parent: self).parse(child_node)
when 'cxnSp'
@shape = ConnectionShape.new(parent: self).parse(child_node)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"child_node",
"|",
"case",
"child_node",
".",
"name",
"when",
"'from'",
"@from",
"=",
"XlsxDrawingPositionParameters",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"child_node",
")",
"when",
"'to'",
"@to",
"=",
"XlsxDrawingPositionParameters",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"child_node",
")",
"when",
"'sp'",
"@shape",
"=",
"DocxShape",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"child_node",
")",
"when",
"'grpSp'",
"@grouping",
"=",
"ShapesGrouping",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"child_node",
")",
"when",
"'pic'",
"@picture",
"=",
"DocxPicture",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"child_node",
")",
"when",
"'graphicFrame'",
"@graphic_frame",
"=",
"GraphicFrame",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"child_node",
")",
"when",
"'cxnSp'",
"@shape",
"=",
"ConnectionShape",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"child_node",
")",
"end",
"end",
"self",
"end"
] | Parse XlsxDrawing object
@param node [Nokogiri::XML:Element] node to parse
@return [XlsxDrawing] result of parsing | [
"Parse",
"XlsxDrawing",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb#L15-L35 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb | OoxmlParser.Borders.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'lnL', 'left'
@left = TableCellLine.new(parent: self).parse(node_child)
when 'lnR', 'right'
@right = TableCellLine.new(parent: self).parse(node_child)
when 'lnT', 'top'
@top = TableCellLine.new(parent: self).parse(node_child)
when 'lnB', 'bottom'
@bottom = TableCellLine.new(parent: self).parse(node_child)
when 'lnTlToBr', 'tl2br'
@top_left_to_bottom_right = TableCellLine.new(parent: self).parse(node_child)
when 'lnBlToTr', 'tr2bl'
@top_right_to_bottom_left = TableCellLine.new(parent: self).parse(node_child)
when 'insideV'
@inner_vertical = TableCellLine.new(parent: self).parse(node_child)
when 'insideH'
@inner_horizontal = TableCellLine.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'lnL', 'left'
@left = TableCellLine.new(parent: self).parse(node_child)
when 'lnR', 'right'
@right = TableCellLine.new(parent: self).parse(node_child)
when 'lnT', 'top'
@top = TableCellLine.new(parent: self).parse(node_child)
when 'lnB', 'bottom'
@bottom = TableCellLine.new(parent: self).parse(node_child)
when 'lnTlToBr', 'tl2br'
@top_left_to_bottom_right = TableCellLine.new(parent: self).parse(node_child)
when 'lnBlToTr', 'tr2bl'
@top_right_to_bottom_left = TableCellLine.new(parent: self).parse(node_child)
when 'insideV'
@inner_vertical = TableCellLine.new(parent: self).parse(node_child)
when 'insideH'
@inner_horizontal = TableCellLine.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'lnL'",
",",
"'left'",
"@left",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'lnR'",
",",
"'right'",
"@right",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'lnT'",
",",
"'top'",
"@top",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'lnB'",
",",
"'bottom'",
"@bottom",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'lnTlToBr'",
",",
"'tl2br'",
"@top_left_to_bottom_right",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'lnBlToTr'",
",",
"'tr2bl'",
"@top_right_to_bottom_left",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'insideV'",
"@inner_vertical",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'insideH'",
"@inner_horizontal",
"=",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse Borders object
@param node [Nokogiri::XML:Element] node to parse
@return [Borders] result of parsing | [
"Parse",
"Borders",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb#L66-L88 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb | OoxmlParser.SlideHelper.transform_of_object | def transform_of_object(object)
case object
when :image
elements.find { |e| e.is_a? Picture }.properties.transform
when :chart
elements.find { |e| e.is_a? GraphicFrame }.transform
when :table
elements.find { |e| e.is_a? GraphicFrame }.transform
when :shape
elements.find { |e| !e.shape_properties.preset.nil? }.shape_properties.transform
else
raise "Dont know this type object - #{object}"
end
end | ruby | def transform_of_object(object)
case object
when :image
elements.find { |e| e.is_a? Picture }.properties.transform
when :chart
elements.find { |e| e.is_a? GraphicFrame }.transform
when :table
elements.find { |e| e.is_a? GraphicFrame }.transform
when :shape
elements.find { |e| !e.shape_properties.preset.nil? }.shape_properties.transform
else
raise "Dont know this type object - #{object}"
end
end | [
"def",
"transform_of_object",
"(",
"object",
")",
"case",
"object",
"when",
":image",
"elements",
".",
"find",
"{",
"|",
"e",
"|",
"e",
".",
"is_a?",
"Picture",
"}",
".",
"properties",
".",
"transform",
"when",
":chart",
"elements",
".",
"find",
"{",
"|",
"e",
"|",
"e",
".",
"is_a?",
"GraphicFrame",
"}",
".",
"transform",
"when",
":table",
"elements",
".",
"find",
"{",
"|",
"e",
"|",
"e",
".",
"is_a?",
"GraphicFrame",
"}",
".",
"transform",
"when",
":shape",
"elements",
".",
"find",
"{",
"|",
"e",
"|",
"!",
"e",
".",
"shape_properties",
".",
"preset",
".",
"nil?",
"}",
".",
"shape_properties",
".",
"transform",
"else",
"raise",
"\"Dont know this type object - #{object}\"",
"end",
"end"
] | Get transform property of object, by object type
@param object [Symbol] type of object: :image, :chart, :table, :shape
@return [OOXMLDocumentObject] needed object | [
"Get",
"transform",
"property",
"of",
"object",
"by",
"object",
"type"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb#L15-L28 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/blip_fill.rb | OoxmlParser.BlipFill.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blip'
@blip = Blip.new(parent: self).parse(node_child)
when 'stretch'
@stretch = Stretch.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blip'
@blip = Blip.new(parent: self).parse(node_child)
when 'stretch'
@stretch = Stretch.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'blip'",
"@blip",
"=",
"Blip",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'stretch'",
"@stretch",
"=",
"Stretch",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse BlipFill object
@param node [Nokogiri::XML:Element] node to parse
@return [BlipFill] result of parsing | [
"Parse",
"BlipFill",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/blip_fill.rb#L12-L22 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb | OoxmlParser.OldDocxShapeProperties.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'fillcolor'
@fill_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
when 'opacity'
@opacity = value.value.to_f
when 'strokecolor'
@stroke_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
when 'strokeweight'
@stroke_weight = value.value.to_f
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'fillcolor'
@fill_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
when 'opacity'
@opacity = value.value.to_f
when 'strokecolor'
@stroke_color = Color.new(parent: self).parse_hex_string(value.value.delete('#'))
when 'strokeweight'
@stroke_weight = value.value.to_f
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'fillcolor'",
"@fill_color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_hex_string",
"(",
"value",
".",
"value",
".",
"delete",
"(",
"'#'",
")",
")",
"when",
"'opacity'",
"@opacity",
"=",
"value",
".",
"value",
".",
"to_f",
"when",
"'strokecolor'",
"@stroke_color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_hex_string",
"(",
"value",
".",
"value",
".",
"delete",
"(",
"'#'",
")",
")",
"when",
"'strokeweight'",
"@stroke_weight",
"=",
"value",
".",
"value",
".",
"to_f",
"end",
"end",
"self",
"end"
] | Parse OldDocxShapeProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [OldDocxShapeProperties] result of parsing | [
"Parse",
"OldDocxShapeProperties",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb#L9-L23 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb | OoxmlParser.Slide.parse | def parse
OOXMLDocumentObject.add_to_xmls_stack(@xml_path)
@name = File.basename(@xml_path, '.*')
node = parse_xml(OOXMLDocumentObject.current_xml)
node.xpath('//p:sld/*').each do |node_child|
case node_child.name
when 'cSld'
@common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
when 'timing'
@timing = Timing.new(parent: self).parse(node_child)
when 'transition'
@transition = Transition.new(parent: self).parse(node_child)
when 'AlternateContent'
@alternate_content = PresentationAlternateContent.new(parent: self).parse(node_child)
end
end
OOXMLDocumentObject.xmls_stack.pop
@relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}#{File.dirname(@xml_path)}/_rels/#{@name}.xml.rels")
parse_note
self
end | ruby | def parse
OOXMLDocumentObject.add_to_xmls_stack(@xml_path)
@name = File.basename(@xml_path, '.*')
node = parse_xml(OOXMLDocumentObject.current_xml)
node.xpath('//p:sld/*').each do |node_child|
case node_child.name
when 'cSld'
@common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
when 'timing'
@timing = Timing.new(parent: self).parse(node_child)
when 'transition'
@transition = Transition.new(parent: self).parse(node_child)
when 'AlternateContent'
@alternate_content = PresentationAlternateContent.new(parent: self).parse(node_child)
end
end
OOXMLDocumentObject.xmls_stack.pop
@relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}#{File.dirname(@xml_path)}/_rels/#{@name}.xml.rels")
parse_note
self
end | [
"def",
"parse",
"OOXMLDocumentObject",
".",
"add_to_xmls_stack",
"(",
"@xml_path",
")",
"@name",
"=",
"File",
".",
"basename",
"(",
"@xml_path",
",",
"'.*'",
")",
"node",
"=",
"parse_xml",
"(",
"OOXMLDocumentObject",
".",
"current_xml",
")",
"node",
".",
"xpath",
"(",
"'//p:sld/*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'cSld'",
"@common_slide_data",
"=",
"CommonSlideData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'timing'",
"@timing",
"=",
"Timing",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'transition'",
"@transition",
"=",
"Transition",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'AlternateContent'",
"@alternate_content",
"=",
"PresentationAlternateContent",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"OOXMLDocumentObject",
".",
"xmls_stack",
".",
"pop",
"@relationships",
"=",
"Relationships",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_file",
"(",
"\"#{OOXMLDocumentObject.path_to_folder}#{File.dirname(@xml_path)}/_rels/#{@name}.xml.rels\"",
")",
"parse_note",
"self",
"end"
] | Parse Slide object
@return [Slide] result of parsing | [
"Parse",
"Slide",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb#L48-L68 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb | OoxmlParser.DocxPicture.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blipFill'
@path_to_image = DocxBlip.new(parent: self).parse(node_child)
when 'spPr'
@properties = DocxShapeProperties.new(parent: self).parse(node_child)
when 'nvPicPr'
@non_visual_properties = NonVisualShapeProperties.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blipFill'
@path_to_image = DocxBlip.new(parent: self).parse(node_child)
when 'spPr'
@properties = DocxShapeProperties.new(parent: self).parse(node_child)
when 'nvPicPr'
@non_visual_properties = NonVisualShapeProperties.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'blipFill'",
"@path_to_image",
"=",
"DocxBlip",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'spPr'",
"@properties",
"=",
"DocxShapeProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'nvPicPr'",
"@non_visual_properties",
"=",
"NonVisualShapeProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse DocxPicture object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxPicture] result of parsing | [
"Parse",
"DocxPicture",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb#L15-L27 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb | OoxmlParser.GradientColor.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'gsLst'
node_child.xpath('*').each do |gradient_stop_node|
@gradient_stops << GradientStop.new(parent: self).parse(gradient_stop_node)
end
when 'path'
@path = node_child.attribute('path').value.to_sym
when 'lin'
@linear_gradient = LinearGradient.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'gsLst'
node_child.xpath('*').each do |gradient_stop_node|
@gradient_stops << GradientStop.new(parent: self).parse(gradient_stop_node)
end
when 'path'
@path = node_child.attribute('path').value.to_sym
when 'lin'
@linear_gradient = LinearGradient.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'gsLst'",
"node_child",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"gradient_stop_node",
"|",
"@gradient_stops",
"<<",
"GradientStop",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"gradient_stop_node",
")",
"end",
"when",
"'path'",
"@path",
"=",
"node_child",
".",
"attribute",
"(",
"'path'",
")",
".",
"value",
".",
"to_sym",
"when",
"'lin'",
"@linear_gradient",
"=",
"LinearGradient",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse GradientColor object
@param node [Nokogiri::XML:Element] node to parse
@return [GradientColor] result of parsing | [
"Parse",
"GradientColor",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb#L18-L32 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs/tab.rb | OoxmlParser.Tab.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'algn', 'val'
@value = value_to_symbol(value)
when 'leader'
@leader = value_to_symbol(value)
when 'pos'
@position = OoxmlSize.new(value.value.to_f, position_unit(node))
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'algn', 'val'
@value = value_to_symbol(value)
when 'leader'
@leader = value_to_symbol(value)
when 'pos'
@position = OoxmlSize.new(value.value.to_f, position_unit(node))
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'algn'",
",",
"'val'",
"@value",
"=",
"value_to_symbol",
"(",
"value",
")",
"when",
"'leader'",
"@leader",
"=",
"value_to_symbol",
"(",
"value",
")",
"when",
"'pos'",
"@position",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
"position_unit",
"(",
"node",
")",
")",
"end",
"end",
"self",
"end"
] | Parse ParagraphTab object
@param node [Nokogiri::XML:Element] node to parse
@return [ParagraphTab] result of parsing | [
"Parse",
"ParagraphTab",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/tabs/tab.rb#L16-L28 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/table_style_info.rb | OoxmlParser.TableStyleInfo.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'name'
@name = value.value.to_s
when 'showColumnStripes'
@show_column_stripes = attribute_enabled?(value)
when 'showFirstColumn'
@show_first_column = attribute_enabled?(value)
when 'showLastColumn'
@show_last_column = attribute_enabled?(value)
when 'showRowStripes'
@show_row_stripes = attribute_enabled?(value)
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'name'
@name = value.value.to_s
when 'showColumnStripes'
@show_column_stripes = attribute_enabled?(value)
when 'showFirstColumn'
@show_first_column = attribute_enabled?(value)
when 'showLastColumn'
@show_last_column = attribute_enabled?(value)
when 'showRowStripes'
@show_row_stripes = attribute_enabled?(value)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'name'",
"@name",
"=",
"value",
".",
"value",
".",
"to_s",
"when",
"'showColumnStripes'",
"@show_column_stripes",
"=",
"attribute_enabled?",
"(",
"value",
")",
"when",
"'showFirstColumn'",
"@show_first_column",
"=",
"attribute_enabled?",
"(",
"value",
")",
"when",
"'showLastColumn'",
"@show_last_column",
"=",
"attribute_enabled?",
"(",
"value",
")",
"when",
"'showRowStripes'",
"@show_row_stripes",
"=",
"attribute_enabled?",
"(",
"value",
")",
"end",
"end",
"self",
"end"
] | Parse TableStyleInfo data
@param [Nokogiri::XML:Element] node with TableStyleInfo data
@return [TableStyleInfo] value of TableStyleInfo data | [
"Parse",
"TableStyleInfo",
"data"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/table_style_info.rb#L23-L39 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/field_simple.rb | OoxmlParser.FieldSimple.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'instr'
@instruction = value.value.to_s
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'r'
@runs << ParagraphRun.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'instr'
@instruction = value.value.to_s
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'r'
@runs << ParagraphRun.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'instr'",
"@instruction",
"=",
"value",
".",
"value",
".",
"to_s",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'r'",
"@runs",
"<<",
"ParagraphRun",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse FieldSimple object
@param node [Nokogiri::XML:Element] node to parse
@return [FieldSimple] result of parsing | [
"Parse",
"FieldSimple",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/field_simple.rb#L17-L32 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/presentation_pattern.rb | OoxmlParser.PresentationPattern.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 'prst'
@preset = value.value.to_sym
end
end
node.xpath('*').each do |color_node|
case color_node.name
when 'fgClr'
@foreground_color = Color.new(parent: self).parse_color(color_node.xpath('*').first)
when 'bgClr'
@background_color = Color.new(parent: self).parse_color(color_node.xpath('*').first)
end
end
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 'prst'
@preset = value.value.to_sym
end
end
node.xpath('*').each do |color_node|
case color_node.name
when 'fgClr'
@foreground_color = Color.new(parent: self).parse_color(color_node.xpath('*').first)
when 'bgClr'
@background_color = Color.new(parent: self).parse_color(color_node.xpath('*').first)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'prst'",
"@preset",
"=",
"value",
".",
"value",
".",
"to_sym",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"color_node",
"|",
"case",
"color_node",
".",
"name",
"when",
"'fgClr'",
"@foreground_color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color",
"(",
"color_node",
".",
"xpath",
"(",
"'*'",
")",
".",
"first",
")",
"when",
"'bgClr'",
"@background_color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color",
"(",
"color_node",
".",
"xpath",
"(",
"'*'",
")",
".",
"first",
")",
"end",
"end",
"self",
"end"
] | Parse PresentationPattern object
@param node [Nokogiri::XML:Element] node to parse
@return [PresentationPattern] result of parsing | [
"Parse",
"PresentationPattern",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/presentation_pattern.rb#L9-L26 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/docx_parser/docx_data/document_structure/document_settings.rb | OoxmlParser.DocumentSettings.parse | def parse
settings_path = OOXMLDocumentObject.path_to_folder + 'word/settings.xml'
return nil unless File.exist?(settings_path)
doc = parse_xml(settings_path)
doc.xpath('w:settings/*').each do |node_child|
case node_child.name
when 'defaultTabStop'
@default_tab_stop = OoxmlSize.new.parse(node_child)
end
end
self
end | ruby | def parse
settings_path = OOXMLDocumentObject.path_to_folder + 'word/settings.xml'
return nil unless File.exist?(settings_path)
doc = parse_xml(settings_path)
doc.xpath('w:settings/*').each do |node_child|
case node_child.name
when 'defaultTabStop'
@default_tab_stop = OoxmlSize.new.parse(node_child)
end
end
self
end | [
"def",
"parse",
"settings_path",
"=",
"OOXMLDocumentObject",
".",
"path_to_folder",
"+",
"'word/settings.xml'",
"return",
"nil",
"unless",
"File",
".",
"exist?",
"(",
"settings_path",
")",
"doc",
"=",
"parse_xml",
"(",
"settings_path",
")",
"doc",
".",
"xpath",
"(",
"'w:settings/*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'defaultTabStop'",
"@default_tab_stop",
"=",
"OoxmlSize",
".",
"new",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse Settings object
@return [DocumentSettings] result of parsing | [
"Parse",
"Settings",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_settings.rb#L9-L21 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/table_cell_line/line_join.rb | OoxmlParser.LineJoin.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'round', 'bevel'
@type = node_child.name.to_sym
when 'miter'
@type = :miter
@limit = node_child.attribute('lim').value.to_f
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'round', 'bevel'
@type = node_child.name.to_sym
when 'miter'
@type = :miter
@limit = node_child.attribute('lim').value.to_f
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'round'",
",",
"'bevel'",
"@type",
"=",
"node_child",
".",
"name",
".",
"to_sym",
"when",
"'miter'",
"@type",
"=",
":miter",
"@limit",
"=",
"node_child",
".",
"attribute",
"(",
"'lim'",
")",
".",
"value",
".",
"to_f",
"end",
"end",
"self",
"end"
] | Parse LineJoin object
@param node [Nokogiri::XML:Element] node to parse
@return [LineJoin] result of parsing | [
"Parse",
"LineJoin",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/table_cell_line/line_join.rb#L8-L19 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list.rb | OoxmlParser.ExtensionList.parse | def parse(node)
node.xpath('*').each do |column_node|
case column_node.name
when 'ext'
@extension_array << Extension.new(parent: self).parse(column_node)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |column_node|
case column_node.name
when 'ext'
@extension_array << Extension.new(parent: self).parse(column_node)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"column_node",
"|",
"case",
"column_node",
".",
"name",
"when",
"'ext'",
"@extension_array",
"<<",
"Extension",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"column_node",
")",
"end",
"end",
"self",
"end"
] | Parse ExtensionList data
@param [Nokogiri::XML:Element] node with ExtensionList data
@return [ExtensionList] value of ExtensionList data | [
"Parse",
"ExtensionList",
"data"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list.rb#L20-L28 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb | OoxmlParser.XlsxCell.parse | def parse(node)
node.attributes.each do |key, value|
case key
when 's'
@style_index = value.value.to_i
when 't'
@type = value.value.to_s
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'f'
@formula = Formula.new(parent: self).parse(node_child)
when 'v'
@value = TextValue.new(parent: self).parse(node_child)
end
end
parse_text_data
self
end | ruby | def parse(node)
node.attributes.each do |key, value|
case key
when 's'
@style_index = value.value.to_i
when 't'
@type = value.value.to_s
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'f'
@formula = Formula.new(parent: self).parse(node_child)
when 'v'
@value = TextValue.new(parent: self).parse(node_child)
end
end
parse_text_data
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'s'",
"@style_index",
"=",
"value",
".",
"value",
".",
"to_i",
"when",
"'t'",
"@type",
"=",
"value",
".",
"value",
".",
"to_s",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'f'",
"@formula",
"=",
"Formula",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'v'",
"@value",
"=",
"TextValue",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"parse_text_data",
"self",
"end"
] | Parse XlsxCell object
@param node [Nokogiri::XML:Element] node to parse
@return [XlsxCell] result of parsing | [
"Parse",
"XlsxCell",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb#L25-L44 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb | OoxmlParser.XlsxCell.get_shared_string | def get_shared_string(value)
return '' if value == ''
string = root_object.shared_strings_table.string_indexes[value.to_i]
@character = string.run
@raw_text = string.text
end | ruby | def get_shared_string(value)
return '' if value == ''
string = root_object.shared_strings_table.string_indexes[value.to_i]
@character = string.run
@raw_text = string.text
end | [
"def",
"get_shared_string",
"(",
"value",
")",
"return",
"''",
"if",
"value",
"==",
"''",
"string",
"=",
"root_object",
".",
"shared_strings_table",
".",
"string_indexes",
"[",
"value",
".",
"to_i",
"]",
"@character",
"=",
"string",
".",
"run",
"@raw_text",
"=",
"string",
".",
"text",
"end"
] | Get shared string by it's number
@return [Nothing] | [
"Get",
"shared",
"string",
"by",
"it",
"s",
"number"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb#L74-L80 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data/shape_tree.rb | OoxmlParser.ShapeTree.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'sp'
@elements << DocxShape.new(parent: self).parse(node_child).dup
when 'pic'
@elements << DocxPicture.new(parent: self).parse(node_child)
when 'graphicFrame'
@elements << GraphicFrame.new(parent: self).parse(node_child)
when 'grpSp'
@elements << ShapesGrouping.new(parent: self).parse(node_child)
when 'cxnSp'
@elements << ConnectionShape.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'sp'
@elements << DocxShape.new(parent: self).parse(node_child).dup
when 'pic'
@elements << DocxPicture.new(parent: self).parse(node_child)
when 'graphicFrame'
@elements << GraphicFrame.new(parent: self).parse(node_child)
when 'grpSp'
@elements << ShapesGrouping.new(parent: self).parse(node_child)
when 'cxnSp'
@elements << ConnectionShape.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'sp'",
"@elements",
"<<",
"DocxShape",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
".",
"dup",
"when",
"'pic'",
"@elements",
"<<",
"DocxPicture",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'graphicFrame'",
"@elements",
"<<",
"GraphicFrame",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'grpSp'",
"@elements",
"<<",
"ShapesGrouping",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'cxnSp'",
"@elements",
"<<",
"ConnectionShape",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse ShapeTree object
@param node [Nokogiri::XML:Element] node to parse
@return [ShapeTree] result of parsing | [
"Parse",
"ShapeTree",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data/shape_tree.rb#L15-L31 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_notes.rb | OoxmlParser.PresentationNotes.parse | def parse(file)
node = parse_xml(file)
node.xpath('p:notes/*').each do |node_child|
case node_child.name
when 'cSld'
@common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
end
end
self
end | ruby | def parse(file)
node = parse_xml(file)
node.xpath('p:notes/*').each do |node_child|
case node_child.name
when 'cSld'
@common_slide_data = CommonSlideData.new(parent: self).parse(node_child)
end
end
self
end | [
"def",
"parse",
"(",
"file",
")",
"node",
"=",
"parse_xml",
"(",
"file",
")",
"node",
".",
"xpath",
"(",
"'p:notes/*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'cSld'",
"@common_slide_data",
"=",
"CommonSlideData",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] | Parse PresentationNotes object
@param file [String] file to parse
@return [PresentationNotes] result of parsing | [
"Parse",
"PresentationNotes",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/presentation_notes.rb#L10-L19 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/target_element.rb | OoxmlParser.TargetElement.parse | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'sldTgt'
@type = :slide
when 'sndTgt'
@type = :sound
@name = node_child.attribute('name').value
@built_in = node_child.attribute('builtIn').value ? StringHelper.to_bool(node_child.attribute('builtIn').value) : false
when 'spTgt'
@type = :shape
@id = node_child.attribute('spid').value
when 'inkTgt'
@type = :ink
@id = node_child.attribute('spid').value
end
end
self
end | ruby | def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'sldTgt'
@type = :slide
when 'sndTgt'
@type = :sound
@name = node_child.attribute('name').value
@built_in = node_child.attribute('builtIn').value ? StringHelper.to_bool(node_child.attribute('builtIn').value) : false
when 'spTgt'
@type = :shape
@id = node_child.attribute('spid').value
when 'inkTgt'
@type = :ink
@id = node_child.attribute('spid').value
end
end
self
end | [
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'sldTgt'",
"@type",
"=",
":slide",
"when",
"'sndTgt'",
"@type",
"=",
":sound",
"@name",
"=",
"node_child",
".",
"attribute",
"(",
"'name'",
")",
".",
"value",
"@built_in",
"=",
"node_child",
".",
"attribute",
"(",
"'builtIn'",
")",
".",
"value",
"?",
"StringHelper",
".",
"to_bool",
"(",
"node_child",
".",
"attribute",
"(",
"'builtIn'",
")",
".",
"value",
")",
":",
"false",
"when",
"'spTgt'",
"@type",
"=",
":shape",
"@id",
"=",
"node_child",
".",
"attribute",
"(",
"'spid'",
")",
".",
"value",
"when",
"'inkTgt'",
"@type",
"=",
":ink",
"@id",
"=",
"node_child",
".",
"attribute",
"(",
"'spid'",
")",
".",
"value",
"end",
"end",
"self",
"end"
] | Parse TargetElement object
@param node [Nokogiri::XML:Element] node to parse
@return [TargetElement] result of parsing | [
"Parse",
"TargetElement",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/target_element.rb#L14-L32 | train |
ONLYOFFICE/ooxml_parser | lib/ooxml_parser/common_parser/common_data/table.rb | OoxmlParser.Table.parse | def parse(node,
number = 0,
default_table_properties = TableProperties.new)
table_properties = default_table_properties.dup
table_properties.jc = :left
node.xpath('*').each do |node_child|
case node_child.name
when 'tblGrid'
@grid = TableGrid.new(parent: self).parse(node_child)
when 'tr'
@rows << TableRow.new(parent: self).parse(node_child)
when 'tblPr'
@properties = TableProperties.new(parent: self).parse(node_child)
end
end
@number = number
self
end | ruby | def parse(node,
number = 0,
default_table_properties = TableProperties.new)
table_properties = default_table_properties.dup
table_properties.jc = :left
node.xpath('*').each do |node_child|
case node_child.name
when 'tblGrid'
@grid = TableGrid.new(parent: self).parse(node_child)
when 'tr'
@rows << TableRow.new(parent: self).parse(node_child)
when 'tblPr'
@properties = TableProperties.new(parent: self).parse(node_child)
end
end
@number = number
self
end | [
"def",
"parse",
"(",
"node",
",",
"number",
"=",
"0",
",",
"default_table_properties",
"=",
"TableProperties",
".",
"new",
")",
"table_properties",
"=",
"default_table_properties",
".",
"dup",
"table_properties",
".",
"jc",
"=",
":left",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'tblGrid'",
"@grid",
"=",
"TableGrid",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tr'",
"@rows",
"<<",
"TableRow",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblPr'",
"@properties",
"=",
"TableProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"@number",
"=",
"number",
"self",
"end"
] | Parse Table object
@param node [Nokogiri::XML:Element] node to parse
@return [Table] result of parsing | [
"Parse",
"Table",
"object"
] | 08452315cde52fa94d8cb3e1eff1db4ea33abc88 | https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table.rb#L28-L45 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.