Class: CWG::BookDetails

Inherits:
Object
  • Object
show all
Defined in:
/Users/martyn/cw/cw_clone/lib/cw/book_details.rb

Constant Summary

HERE =
File.dirname(__FILE__) + '/'
GEM_BOOK_DIRECTORY =
HERE + '../../data/text/'
GEM_BOOK_NAME =
'book.txt'
DEFAULT_BOOK_DIRECTORY =
'books'

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (BookDetails) initialize

Returns a new instance of BookDetails



14
15
16
17
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 14

def initialize
  book_directory
  book_name
end

Instance Attribute Details

- (Object) args (readonly)

Returns the value of attribute args



7
8
9
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 7

def args
  @args
end

Instance Method Details

- (Object) arguments(args)



44
45
46
47
48
49
50
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 44

def arguments args
  @args = args
  @args[:output] = :letter unless @args[:output]
  if @args[:duration]
    @timeout = Time.now + @args[:duration] * 60.0
  end
end

- (Object) book_directory



32
33
34
35
36
37
38
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 32

def book_directory
  book_dir = GEM_BOOK_DIRECTORY
  if is_default_book_dir?
    book_dir = DEFAULT_BOOK_DIRECTORY
  end
  Params.book_dir ||= book_dir
end

- (Object) book_location



40
41
42
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 40

def book_location
  temp = File.expand_path(book_name, book_directory)
end

- (Object) book_name



28
29
30
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 28

def book_name
  Params.book_name ||= GEM_BOOK_NAME
end

- (Boolean) book_timeout?

Returns:

  • (Boolean)


68
69
70
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 68

def book_timeout?
  @timeout && (Time.now > @timeout)
end

- (Boolean) is_default_book_dir?

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 19

def is_default_book_dir?
  if File.exist? DEFAULT_BOOK_DIRECTORY
    if File.directory? DEFAULT_BOOK_DIRECTORY
      return true
    end
  end
  false
end

- (Boolean) sentences_complete?

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 56

def sentences_complete?
  if @args.has_key?(:sentences) &&  @args[:sentences].is_a?(Fixnum)
    if @sentence_count_source
      @sentence_count_source = nil
    else
      @args[:sentences] -= 1
      @sentence_count_source = true
    end
    true if(@args[:sentences] < 0)
  end
end

- (Boolean) session_finished?

Returns:

  • (Boolean)


52
53
54
# File '/Users/martyn/cw/cw_clone/lib/cw/book_details.rb', line 52

def session_finished?
  sentences_complete? || book_timeout?
end