Skip to content

Commit

Permalink
Merge pull request #29 from camertron/segmentation
Browse files Browse the repository at this point in the history
Segmentation
  • Loading branch information
tigrish committed Feb 16, 2014
2 parents 96c4602 + 9f38ba3 commit 779e3d5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cldr/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module Export
'RbnfRoot',
'Metazones',
'WindowsZones',
'NumberingSystems'
'NumberingSystems',
'SegmentsRoot'
]

class << self
Expand Down
1 change: 1 addition & 0 deletions lib/cldr/export/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Data
autoload :Rbnf, 'cldr/export/data/rbnf'
autoload :RbnfRoot, 'cldr/export/data/rbnf_root'
autoload :NumberingSystems, 'cldr/export/data/numbering_systems'
autoload :SegmentsRoot, 'cldr/export/data/segments_root'

class << self
def dir
Expand Down
51 changes: 51 additions & 0 deletions lib/cldr/export/data/segments_root.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Cldr
module Export
module Data
class SegmentsRoot < Base

def initialize
super(nil)
update(:segments => segmentations)
end

def segmentations
doc.xpath("ldml/segmentations/segmentation").inject({}) do |ret, seg|
type = seg.attribute("type").value
ret[type] = segmentation(seg)
ret
end
end

def segmentation(node)
{
:variables => variables(node),
:rules => rules(node)
}
end

def variables(node)
(node / "variables" / "variable").map do |variable|
{
:id => variable.attribute("id").value,
:value => variable.text
}
end
end

def rules(node)
(node / "segmentRules" / "rule").map do |rule|
{
:id => rule.attribute("id").value,
:value => rule.text
}
end
end

def path
@path ||= "#{Cldr::Export::Data.dir}/segments/root.xml"
end

end
end
end
end

0 comments on commit 779e3d5

Please sign in to comment.