Class: PlaceInBook
Instance Attribute Summary collapse
-
#chapter ⇒ Object
Returns the value of attribute chapter.
-
#location ⇒ Object
Returns the value of attribute location.
-
#page ⇒ Object
Returns the value of attribute page.
-
#subsection ⇒ Object
Returns the value of attribute subsection.
-
#topic ⇒ Object
Returns the value of attribute topic.
Instance Method Summary collapse
-
#locate_section ⇒ Object
get location in e-book from section.
-
#process_input(input) ⇒ Object
process user input of a page or section.
Instance Attribute Details
#chapter ⇒ Object
Returns the value of attribute chapter.
9 10 11 |
# File 'lib/mobiloc.rb', line 9 def chapter @chapter end |
#location ⇒ Object
Returns the value of attribute location.
9 10 11 |
# File 'lib/mobiloc.rb', line 9 def location @location end |
#page ⇒ Object
Returns the value of attribute page.
9 10 11 |
# File 'lib/mobiloc.rb', line 9 def page @page end |
#subsection ⇒ Object
Returns the value of attribute subsection.
9 10 11 |
# File 'lib/mobiloc.rb', line 9 def subsection @subsection end |
#topic ⇒ Object
Returns the value of attribute topic.
9 10 11 |
# File 'lib/mobiloc.rb', line 9 def topic @topic end |
Instance Method Details
#locate_section ⇒ Object
get location in e-book from section
29 30 31 32 33 34 35 36 37 |
# File 'lib/mobiloc.rb', line 29 def locate_section result_array = $book_data.find_all { |place| place[:chapter]==@chapter && place[:subsection]==@subsection } @place = result_array[0] @location = @place[:location] @topic = @place[:topic] puts "The e-book location is: #{@location}" puts "...and the topic is: #{@topic}." puts "Happy reading" end |
#process_input(input) ⇒ Object
process user input of a page or section
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mobiloc.rb', line 12 def process_input(input) @input = input if @input.include?("sec") @section = @input.gsub("sec ","") @section = @section.split('.') @chapter = @section.first.to_i @subsection = @section.last.to_i puts "Finding section #{@chapter}.#{@subsection}..." elsif @input =~ /^[0-9]+$/ @page = @input.to_i puts "Finding page #{@page}..." else puts "Not a page or section." end end |