Class: Object

Inherits:
BasicObject
Defined in:
lib/srs_game.rb

Constant Summary

TRUE_WORDS =
%w{t true yes y}
FALSE_WORDS =
%w{f false no n}

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) blank?

Returns true if false, nil, or self.empty?

Returns:

  • (Boolean)


17
18
19
# File 'lib/srs_game.rb', line 17

def blank?
  respond_to?(:empty?) ? empty? : !self
end

- (Boolean) boolean?

Can the string be converted to a boolean value?

Returns:

  • (Boolean)


34
35
36
# File 'lib/srs_game.rb', line 34

def boolean?
  !to_bool.nil?
end

- (Object) command_pp

Removes "_" from beginning of line



39
40
41
# File 'lib/srs_game.rb', line 39

def command_pp
  to_s.gsub(/^_/, "")
end

- (Object) to_bool

Convert to boolean value



27
28
29
30
31
# File 'lib/srs_game.rb', line 27

def to_bool
  dc = to_s.downcase
  if TRUE_WORDS.include?(dc) then true
  elsif FALSE_WORDS.include?(dc) then false end # if
end

- (Object) to_sentence(options = {})

From ActiveSupport. Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:

  • :words_connector

    • The sign or word used to join the elements in arrays with two or more elements (default: ", ")

  • :two_words_connector

    • The sign or word used to join the elements in arrays with two elements (default: " and ")

  • :last_word_connector

    • The sign or word used to join the last element in arrays with three or more elements (default: ", and ")

  • :bold

    • Bolds the elements being joined. (default: false)



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/srs_game.rb', line 50

def to_sentence(options = {})
  words_connector = options[:words_connector] ||  ", "
  two_words_connector = options[:two_words_connector] || " and "
  last_word_connector = options[:last_word_connector] || ", and "

  if options[:bold]
    return to_sentence Array[self] unless respond_to? :map!
    map!(&:to_s)
    map!(&:bold)
  end # if

  case length
  when 0
    ""
  when 1
    self[0].to_s.dup
  when 2
    "#{self[0]}#{two_words_connector}#{self[1]}"
  else
    "#{self[0...-1].join(words_connector)}#{last_word_connector}#{self[-1]}"
  end # case
end

- (Boolean) unblank?

Opposite of Object#blank?

Returns:

  • (Boolean)


22
23
24
# File 'lib/srs_game.rb', line 22

def unblank?
  !self.blank?
end