Class: HotelBeds::Parser::ClassMethods::Attribute
- Inherits:
-
Object
- Object
- HotelBeds::Parser::ClassMethods::Attribute
- Defined in:
- lib/hotel_beds/parser.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#custom ⇒ Object
readonly
Returns the value of attribute custom.
-
#multiple ⇒ Object
readonly
Returns the value of attribute multiple.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
Instance Method Summary collapse
-
#initialize(name, parser: nil, selector: nil, attr: :content, multiple: false, &block) ⇒ Attribute
constructor
A new instance of Attribute.
- #retrieve(doc) ⇒ Object
Constructor Details
#initialize(name, parser: nil, selector: nil, attr: :content, multiple: false, &block) ⇒ Attribute
Returns a new instance of Attribute.
13 14 15 16 17 18 19 20 21 |
# File 'lib/hotel_beds/parser.rb', line 13 def initialize(name, parser: nil, selector: nil, attr: :content, multiple: false, &block) self.name = name.to_sym self.parser = parser self.selector = selector self.attr = attr self.multiple = !!multiple self.custom = block freeze end |
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
10 11 12 |
# File 'lib/hotel_beds/parser.rb', line 10 def attr @attr end |
#custom ⇒ Object
Returns the value of attribute custom.
10 11 12 |
# File 'lib/hotel_beds/parser.rb', line 10 def custom @custom end |
#multiple ⇒ Object
Returns the value of attribute multiple.
10 11 12 |
# File 'lib/hotel_beds/parser.rb', line 10 def multiple @multiple end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/hotel_beds/parser.rb', line 10 def name @name end |
#parser ⇒ Object
Returns the value of attribute parser.
10 11 12 |
# File 'lib/hotel_beds/parser.rb', line 10 def parser @parser end |
#selector ⇒ Object
Returns the value of attribute selector.
10 11 12 |
# File 'lib/hotel_beds/parser.rb', line 10 def selector @selector end |
Instance Method Details
#retrieve(doc) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hotel_beds/parser.rb', line 23 def retrieve(doc) return nil if doc.nil? if custom custom.yield(doc) elsif multiple doc.css(selector).map(&method(:read_element)) elsif selector (element = doc.at_css(selector)) && element && read_element(element) or nil else read_element(doc) end end |