Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing PresetColor to GradientStop #213

Merged
merged 1 commit into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* Clean way to parse `ParagraphSpacing`
* `ParagraphTab` now stored in `Tabs` in `ParagraphProperties`
* Add `OoxmlSize` support of `one_240th_cm` and use in `Spacing`
* Add parsing `PresetColor` to `GradientStop`

### Fixes
* Fix parsing document style id - it can be string, not only digit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.parse(gradient_fill_node)
case gradient_fill_node_child.name
when 'gsLst'
gradient_fill_node_child.xpath('*').each do |gradient_stop_node|
gradient_color.gradient_stops << GradientStop.parse(gradient_stop_node)
gradient_color.gradient_stops << GradientStop.new(parent: gradient_color).parse(gradient_stop_node)
end
when 'path'
gradient_color.path = gradient_fill_node_child.attribute('path').value.to_sym
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
require_relative 'gradient_stop/preset_color'
module OoxmlParser
class GradientStop < OOXMLDocumentObject
attr_accessor :position, :color

def initialize(position)
@position = position
end
# Parse GradientStop object
# @param node [Nokogiri::XML:Element] node to parse
# @return [GradientStop] result of parsing
def parse(node)
node.attributes.each do |key, value|
case key
when 'pos'
@position = value.value.to_i / 1_000
end
end

def self.parse(gs_node)
gradient_stop = GradientStop.new(gs_node.attribute('pos').value.to_i / 1_000)
gs_node.xpath('*').each { |color_node| gradient_stop.color = Color.parse_color(color_node) }
gradient_stop
node.xpath('*').each do |node_child|
@color = case node_child.name
when 'prstClr'
PresetColor.new(parent: self).parse(node_child)
else
Color.parse_color(node_child)
end
end
self
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module OoxmlParser
# Class for working with `a:prstClr` tag
class PresetColor < OOXMLDocumentObject
# @return [String] value of preset color
attr_accessor :value

# Parse PresetColor object
# @param node [Nokogiri::XML:Element] node to parse
# @return [PresetColor] result of parsing
def parse(node)
node.attributes.each do |key, value|
case key
when 'val'
@value = value.value.to_s
end
end
self
end
end
end
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'spec_helper'

describe 'My behaviour' do
it 'gradient_fill.xlsx' do
xlsx = OoxmlParser::XlsxParser.parse_xlsx('spec/workbook/worksheet/drawing/shape/properties/fill_color/value/gradient_stops/gradient_stops_color/gradient_stops_color_preset.xlsx')
expect(xlsx.worksheets[0].drawings.first.shape.properties.fill_color.value.gradient_stops.first.color.value).to eq('lightYellow')
end
end