Class: OpenStax::Content::Title
- Inherits:
-
Object
- Object
- OpenStax::Content::Title
- Defined in:
- lib/openstax/content/title.rb
Instance Attribute Summary collapse
-
#book_location ⇒ Object
readonly
Returns the value of attribute book_location.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(title) ⇒ Title
constructor
A new instance of Title.
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_location ⇒ Object (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 |
#text ⇒ Object (readonly)
Returns the value of attribute text.
2 3 4 |
# File 'lib/openstax/content/title.rb', line 2 def text @text end |