Module: OpenStax::Cnx::V1::Baked

Defined in:
lib/openstax/cnx/v1/baked.rb

Class Method Summary collapse

Class Method Details

.parse_title(title) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/openstax/cnx/v1/baked.rb', line 2

def self.parse_title(title)
  return nil if title.nil?

  part = Nokogiri::HTML.fragment(title)
  text_node = part.css('.os-text')
  if !text_node.empty?
    { text: text_node.text, book_location: part.css('.os-number').text.split('.') }
  else
    { text: title, book_location: [] }
  end
end