Class: Fvm::Manipulator

Inherits:
Object
  • Object
show all
Defined in:
lib/fvm/manipulator.rb

Overview

Provides methods to manipulate the markup of a Flex SDK download page into usable data

Instance Method Summary collapse

Instance Method Details

#headers(node) ⇒ Object

Formats table header nodes into an array



24
25
26
# File 'lib/fvm/manipulator.rb', line 24

def headers( node )
  node.xpath( 'table/tbody/tr/th' ).map( &:text ).map( &:strip )
end

#rows(node) ⇒ Object

Formats table rows into an associative array



30
31
32
# File 'lib/fvm/manipulator.rb', line 30

def rows( node )
  node.xpath( 'table/tbody/tr[td]' ).map { |row| row.xpath( 'td' ).map { |node| text_or_link node } }
end

#table(node) ⇒ Object

Formats a table into an array of hashes (rows)



18
19
20
# File 'lib/fvm/manipulator.rb', line 18

def table( node )
  rows( node ).map { |row| Hash[ headers( node ).zip( row ).sort ] }
end

#title(node) ⇒ Object

Formats the title node of a table



12
13
14
# File 'lib/fvm/manipulator.rb', line 12

def title( node )
  node.text.strip
end