Class: OpenStax::Content::Title

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/content/title.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Title

Returns a new instance of Title.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/openstax/content/title.rb', line 4

def initialize(title)
  return if title.nil?

  @text = title

  part = Nokogiri::HTML.fragment(title)
  number_node = part.at_css('.os-number')
  unless number_node.nil?
    @book_location = number_node.text.gsub(/[^\.\d]/, '').split('.').map do |number|
      Integer(number) rescue nil
    end.compact
  end
  @book_location = [] if @book_location.nil?
end

Instance Attribute Details

#book_locationObject (readonly)

Returns the value of attribute book_location.



2
3
4
# File 'lib/openstax/content/title.rb', line 2

def book_location
  @book_location
end

#textObject (readonly)

Returns the value of attribute text.



2
3
4
# File 'lib/openstax/content/title.rb', line 2

def text
  @text
end