Class: Microformat::Parser
- Inherits:
-
Object
- Object
- Microformat::Parser
- Defined in:
- lib/microformat/parser.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(doc, options) ⇒ Parser
constructor
A new instance of Parser.
- #limit ⇒ Object
- #parse(elements) ⇒ Object
- #selectors ⇒ Object
Constructor Details
#initialize(doc, options) ⇒ Parser
Returns a new instance of Parser.
18 19 20 21 22 |
# File 'lib/microformat/parser.rb', line 18 def initialize(doc, ) @doc = doc @options = parse(elements) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
16 17 18 |
# File 'lib/microformat/parser.rb', line 16 def doc @doc end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/microformat/parser.rb', line 16 def @options end |
Class Method Details
.parse(doc, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/microformat/parser.rb', line 7 def self.parse(doc, = {}) # ensure the document is parsed unless doc.respond_to?(:css) doc = Nokogiri::HTML(doc) end # return the collection new(doc, ).collection end |
Instance Method Details
#collection ⇒ Object
39 40 41 |
# File 'lib/microformat/parser.rb', line 39 def collection @collection ||= Collection.new end |
#limit ⇒ Object
31 32 33 |
# File 'lib/microformat/parser.rb', line 31 def limit @limit ||= [:limit] || Float::INFINITY end |
#parse(elements) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/microformat/parser.rb', line 24 def parse(elements) i = 0; while i < [limit, elements.size].min do collection << elements[i] i += 1 end end |