polyrex 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/polyrex.rb +15 -2
  2. metadata +2 -2
data/lib/polyrex.rb CHANGED
@@ -11,10 +11,15 @@ require 'polyrex-object-methods'
11
11
  require 'rexle'
12
12
 
13
13
  class Polyrex
14
+ attr_accessor :summary_fields
14
15
 
15
16
  def initialize(location)
17
+
16
18
  @id = '0'
17
- open(location)
19
+ open(location)
20
+ summary_h = Hash[*@doc.xpath("summary/*").map {|x| [x.name, x.text]}.flatten]
21
+ @summary = OpenStruct.new summary_h
22
+ @summary_fields = summary_h.keys.map(&:to_sym)
18
23
  end
19
24
 
20
25
  def create(id=nil)
@@ -32,10 +37,12 @@ class Polyrex
32
37
  end
33
38
 
34
39
  def to_xml(options={})
40
+ refresh_summary
35
41
  @doc.to_s(options)
36
42
  end
37
43
 
38
44
  def save(filepath=nil)
45
+ refresh_summary
39
46
  filepath ||= @local_filepath
40
47
  @local_filepath = filepath
41
48
  File.open(filepath,'w'){|f| @doc.write f}
@@ -81,7 +88,7 @@ class Polyrex
81
88
  end
82
89
 
83
90
  def summary
84
- OpenStruct.new Hash[*@doc.xpath("summary/*").map {|x| [x.name, x.text]}.flatten]
91
+ @summary
85
92
  end
86
93
 
87
94
  private
@@ -242,5 +249,11 @@ class Polyrex
242
249
 
243
250
  self.instance_eval methodx.join("\n")
244
251
  end
252
+
253
+ def refresh_summary()
254
+ @summary_fields.each do |x|
255
+ @doc.element('summary/' + x.to_s).text = @summary.method(x).call
256
+ end
257
+ end
245
258
 
246
259
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyrex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2011-01-21 00:00:00 +00:00
12
+ date: 2011-01-22 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency