mochigome 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/data_node.rb CHANGED
@@ -82,8 +82,12 @@ module Mochigome
82
82
  end
83
83
  node.add_child(Nokogiri::XML::Comment.new(doc, @comment)) if @comment
84
84
  each do |key, value|
85
- sub_node = Nokogiri::XML::Node.new("datum", doc)
86
- sub_node["name"] = key.to_s.titleize
85
+ if key.to_s.start_with?("_")
86
+ sub_node = Nokogiri::XML::Node.new(key.to_s.sub("_", ""), doc)
87
+ else
88
+ sub_node = Nokogiri::XML::Node.new("datum", doc)
89
+ sub_node["name"] = key.to_s.titleize
90
+ end
87
91
  sub_node.content = value
88
92
  node.add_child(sub_node)
89
93
  end
@@ -95,7 +99,9 @@ module Mochigome
95
99
 
96
100
  # TODO: Should handle trickier situations involving datanodes not having various columns
97
101
  def flat_column_names
98
- colnames = (["name"] + keys).map {|key| "#{@type_name}::#{key}"}
102
+ colnames = (["name"] + keys).
103
+ reject{|key| key.to_s.start_with?("_")}.
104
+ map{|key| "#{@type_name}::#{key}"}
99
105
  choices = @children.map(&:flat_column_names)
100
106
  colnames += choices.max_by(&:size) || []
101
107
  colnames
@@ -103,7 +109,8 @@ module Mochigome
103
109
 
104
110
  # TODO: Should handle trickier situations involving datanodes not having various columns
105
111
  def append_rows_to(table, pad, stack = [])
106
- stack.push([@name] + values)
112
+ row_vals = keys.reject{|k| k.to_s.start_with?("_")}.map{|k| self[k]}
113
+ stack.push([@name] + row_vals)
107
114
  if @children.size > 0
108
115
  @children.each {|child| child.send(:append_rows_to, table, pad, stack)}
109
116
  else
data/lib/mochigome_ver.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mochigome
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -101,7 +101,7 @@ describe Mochigome::DataNode do
101
101
  @datanode.comment = "Foo"
102
102
  @datanode.merge! [{:id => 400}, {:apples => 1}, {:box_cutters => 2}, {:can_openers => 3}]
103
103
  emp1 = @datanode << Mochigome::DataNode.new(:employee, :alice)
104
- emp1.merge! [{:id => 500}, {:x => 9}, {:y => 8}, {:z => 7}, {:internal_type => "Cyborg"}]
104
+ emp1.merge! [{:id => 500}, {:x => 9}, {:y => 8}, {:z => 7}, {:internal_type => "Cyborg"}, {:_foo => "bar"}]
105
105
  emp2 = @datanode << Mochigome::DataNode.new(:employee, :bob)
106
106
  emp2.merge! [{:id => 600}, {:x => 5}, {:y => 4}, {:z => 8734}, {:internal_type => "Human"}]
107
107
  emp2 << Mochigome::DataNode.new(:pet, :lassie)
@@ -122,8 +122,8 @@ describe Mochigome::DataNode do
122
122
  ]
123
123
  end
124
124
 
125
- it "can convert to an XML document with ids, names, types, and internal_types as attributes" do
126
- # Why stringify and reparse it? So that we could switch to another XML generator.
125
+ it "can convert to an XML document with correct attributes and elements" do
126
+ # Why stringify and reparse? So that we could use another XML generator
127
127
  doc = Nokogiri::XML(@datanode.to_xml.to_s)
128
128
 
129
129
  comment = doc.xpath('/node[@type="Corporation"]/comment()').first
@@ -139,8 +139,14 @@ describe Mochigome::DataNode do
139
139
  assert_equal "alice", emp_nodes.first['name']
140
140
  assert_equal "bob", emp_nodes.last['name']
141
141
  assert_equal "Cyborg", emp_nodes.first['internal_type']
142
- assert_equal "4", emp_nodes.last.xpath('./datum[@name="Y"]').first.content
142
+ assert_equal "4", emp_nodes.last.xpath('datum[@name="Y"]').first.content
143
143
  assert_equal "lassie", emp_nodes.last.xpath('node').first['name']
144
+
145
+ # Keys that start with an underscore are to be turned into so-named elems
146
+ assert_empty emp_nodes.first.xpath('datum').select{|datum|
147
+ datum['name'] =~ /foo/i
148
+ }
149
+ assert_equal "bar", emp_nodes.first.xpath('foo').first.content
144
150
  end
145
151
 
146
152
  it "can convert to a flattened Ruport table" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mochigome
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 8
10
- version: 0.1.8
9
+ - 9
10
+ version: 0.1.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Mike Simon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-07 00:00:00 Z
18
+ date: 2012-05-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement