Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/srs_game.rb
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#command_pp ⇒ Object
Removes “_” from beginning of line and downcases it.
-
#to_sentence(options = {}) ⇒ String
From ActiveSupport.
- #unblank? ⇒ Boolean
Instance Method Details
#blank? ⇒ 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_pp ⇒ Object
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)
-
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( = {}) words_connector = [:words_connector] || ", " two_words_connector = [:two_words_connector] || " and " last_word_connector = [:last_word_connector] || ", and " if [: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
26 27 28 |
# File 'lib/srs_game.rb', line 26 def unblank? !self.blank? end |