Mobiloc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/mobiloc.rb +50 -0
  2. metadata +46 -0
data/lib/mobiloc.rb ADDED
@@ -0,0 +1,50 @@
1
+ # Project MobiLoc: Gets e-book location by page or section for Ruby Programming 1.9 book
2
+
3
+ require_relative 'mobidata' # e-book data for first 5 chapters of Programming Ruby 1.9 book
4
+
5
+ class PlaceInBook
6
+
7
+ include Enumerable
8
+
9
+ attr_accessor :chapter, :subsection, :topic, :page, :location
10
+
11
+ # process user input of a page or section
12
+ def process_input(input)
13
+ @input = input
14
+ if @input.include?("sec")
15
+ @section = @input.gsub("sec ","")
16
+ @section = @section.split('.')
17
+ @chapter = @section.first.to_i
18
+ @subsection = @section.last.to_i
19
+ puts "Finding section #{@chapter}.#{@subsection}..."
20
+ elsif
21
+ @input =~ /^[0-9]+$/
22
+ @page = @input.to_i
23
+ puts "Finding page #{@page}..."
24
+ else puts "Not a page or section."
25
+ end
26
+ end
27
+
28
+ # get location in e-book from section
29
+ def locate_section
30
+ result_array = $book_data.find_all { |place| place[:chapter]==@chapter && place[:subsection]==@subsection }
31
+ @place = result_array[0]
32
+ @location = @place[:location]
33
+ @topic = @place[:topic]
34
+ puts "The e-book location is: #{@location}"
35
+ puts "...and the topic is: #{@topic}."
36
+ puts "Happy reading"
37
+ end
38
+
39
+ # get location in e-book from page -- method not yet implemented
40
+ # concept is to interpolate location linearly from page range bounded by two adjacent page entries
41
+
42
+ end # PlaceInBook class end
43
+
44
+ # prompt and take in initial user input
45
+ print "To find a Kindle .mobi location, enter a page number (e.g., 123), or type 'sec' plus a section number (e.g., sec 3.2):"
46
+ entered_text = gets.chomp
47
+ puts "You entered: #{entered_text}"
48
+ pib = PlaceInBook.new
49
+ pib.process_input(entered_text)
50
+ pib.locate_section
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Mobiloc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Emily Allen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Mobiloc: get e-book location by page or section in Ruby Programming
15
+ 1.9 book (Ruby gem class project)'
16
+ email: allenemilyh@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/mobiloc.rb
22
+ homepage: http://rubygems.org/gems/mobiloc
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: ! 'Mobiloc: e-book location tool'
46
+ test_files: []