Class: Object

Inherits:
BasicObject
Defined in:
lib/srs_game.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'lib/srs_game.rb', line 18

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

#command_ppObject

Removes “_” from beginning of line and downcases it



31
32
33
# File 'lib/srs_game.rb', line 31

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

#to_sentence(options = {}) ⇒ String

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)

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/srs_game.rb', line 42

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

  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
end

#unblank?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/srs_game.rb', line 26

def unblank?
  !self.blank?
end