Class: PlaceInBook

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mobiloc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chapterObject

Returns the value of attribute chapter.



9
10
11
# File 'lib/mobiloc.rb', line 9

def chapter
  @chapter
end

#locationObject

Returns the value of attribute location.



9
10
11
# File 'lib/mobiloc.rb', line 9

def location
  @location
end

#pageObject

Returns the value of attribute page.



9
10
11
# File 'lib/mobiloc.rb', line 9

def page
  @page
end

#subsectionObject

Returns the value of attribute subsection.



9
10
11
# File 'lib/mobiloc.rb', line 9

def subsection
  @subsection
end

#topicObject

Returns the value of attribute topic.



9
10
11
# File 'lib/mobiloc.rb', line 9

def topic
  @topic
end

Instance Method Details

#locate_sectionObject

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