Class: MicroMicro::Document
- Inherits:
-
Object
- Object
- MicroMicro::Document
- Defined in:
- lib/micro_micro/document.rb
Instance Method Summary collapse
-
#initialize(markup, base_url) ⇒ Document
constructor
Parse a string of HTML for microformats2-encoded data.
-
#inspect ⇒ String
:nocov:.
-
#items ⇒ MicroMicro::Collections::ItemsCollection
A collection of Items parsed from the provided markup.
-
#relationships ⇒ MicroMicro::Collections::RelationshipsCollection
A collection of Relationships parsed from the provided markup.
-
#to_h ⇒ Hash{Symbol => Array, Hash}
Return the parsed document as a Hash.
Constructor Details
#initialize(markup, base_url) ⇒ Document
Parse a string of HTML for microformats2-encoded data.
18 19 20 |
# File 'lib/micro_micro/document.rb', line 18 def initialize(markup, base_url) @document = Nokogiri::HTML5::Document.parse(markup, base_url).resolve_relative_urls! end |
Instance Method Details
#inspect ⇒ String
:nocov:
25 26 27 28 29 |
# File 'lib/micro_micro/document.rb', line 25 def inspect "#<#{self.class}:#{format('%#0x', object_id)} " \ "items: #{items.inspect}, " \ "relationships: #{relationships.inspect}>" end |
#items ⇒ MicroMicro::Collections::ItemsCollection
A collection of Items parsed from the provided markup.
35 36 37 |
# File 'lib/micro_micro/document.rb', line 35 def items @items ||= Collections::ItemsCollection.new(Item.from_context(document.element_children)) end |
#relationships ⇒ MicroMicro::Collections::RelationshipsCollection
A collection of Relationships parsed from the provided markup.
42 43 44 |
# File 'lib/micro_micro/document.rb', line 42 def relationships @relationships ||= Collections::RelationshipsCollection.new(Relationship.from_context(document)) end |
#to_h ⇒ Hash{Symbol => Array, Hash}
Return the parsed document as a Hash.
56 57 58 59 60 61 62 |
# File 'lib/micro_micro/document.rb', line 56 def to_h { items: items.to_a, rels: relationships.group_by_rel, "rel-urls": relationships.group_by_url } end |