microformat 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,12 +30,21 @@ module Microformat
30
30
  def read_value_from(document)
31
31
  Array(options[:attribute] || "text").each do |attr|
32
32
  if attr == "text"
33
- return document.text
33
+ return cast(document.text || options[:default], options[:cast])
34
34
  elsif document[attr]
35
- return document[attr]
35
+ return cast(document[attr], options[:cast])
36
36
  end
37
37
  end
38
- return nil
38
+ return options[:default]
39
+ end
40
+
41
+ def cast(value, cast_to = nil)
42
+ value && case cast_to
43
+ when :integer then value.to_i
44
+ when :decimal then value.to_f
45
+ when :string then value.to_s
46
+ else value
47
+ end
39
48
  end
40
49
  end
41
50
  end
@@ -0,0 +1,16 @@
1
+ require "microformat/format"
2
+ require "microformat/card"
3
+
4
+ module Microformat
5
+ class ReviewAggregate < Format
6
+ selector ".hreview-aggregate"
7
+
8
+ attribute_definition do |root|
9
+ root.attribute(:item, format: Card)
10
+ root.attribute(:rating, cast: :decimal)
11
+ root.attribute(:count, cast: :integer)
12
+ root.attribute(:votes, cast: :integer)
13
+ root.attribute(:summary)
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Microformat
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microformat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -98,6 +98,7 @@ files:
98
98
  - lib/microformat/format.rb
99
99
  - lib/microformat/parser.rb
100
100
  - lib/microformat/review.rb
101
+ - lib/microformat/review_aggregate.rb
101
102
  - lib/microformat/selectors.rb
102
103
  - lib/microformat/version.rb
103
104
  - microformat.gemspec
@@ -124,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  segments:
126
127
  - 0
127
- hash: -2467505088189709361
128
+ hash: -2579108648262463692
128
129
  required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  none: false
130
131
  requirements:
@@ -133,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  segments:
135
136
  - 0
136
- hash: -2467505088189709361
137
+ hash: -2579108648262463692
137
138
  requirements: []
138
139
  rubyforge_project:
139
140
  rubygems_version: 1.8.24