Class: Gitt::Parsers::Attributer
- Inherits:
-
Object
- Object
- Gitt::Parsers::Attributer
- Defined in:
- lib/gitt/parsers/attributer.rb
Overview
Extracts attributes from XML formatted content.
Class Method Summary collapse
Instance Method Summary collapse
- #call(content) ⇒ Object
-
#initialize(keys = Core::EMPTY_ARRAY) ⇒ Attributer
constructor
A new instance of Attributer.
Constructor Details
#initialize(keys = Core::EMPTY_ARRAY) ⇒ Attributer
Returns a new instance of Attributer.
11 12 13 |
# File 'lib/gitt/parsers/attributer.rb', line 11 def initialize keys = Core::EMPTY_ARRAY @keys = keys end |
Class Method Details
.with ⇒ Object
9 |
# File 'lib/gitt/parsers/attributer.rb', line 9 def self.with(...) = new(...) |
Instance Method Details
#call(content) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/gitt/parsers/attributer.rb', line 15 def call content scrub = String(content).scrub "?" keys.reduce({}) do |attributes, key| attributes.merge key => scrub[%r(<#{key}>(?<value>.*?)</#{key}>)m, :value] end end |