Class: Gitt::Parsers::Attributer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitt/parsers/attributer.rb

Overview

Extracts attributes from XML formatted content.

Class Method Summary collapse

Instance Method Summary collapse

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

.withObject



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