Class: ContentSpinning::Spinner
- Inherits:
-
Array
- Object
- Array
- ContentSpinning::Spinner
- Defined in:
- lib/content_spinning/spinner.rb
Instance Method Summary collapse
- #cleaned ⇒ Object
- #count ⇒ Object
-
#initialize(*items) ⇒ Spinner
constructor
A new instance of Spinner.
- #inspect ⇒ Object
- #random ⇒ Object
- #spin ⇒ Object
- #to_source ⇒ Object
Constructor Details
#initialize(*items) ⇒ Spinner
Returns a new instance of Spinner.
6 7 8 |
# File 'lib/content_spinning/spinner.rb', line 6 def initialize(*items) push(*items) end |
Instance Method Details
#cleaned ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/content_spinning/spinner.rb', line 10 def cleaned map!(&:cleaned) uniq! if length == 1 first else self end end |
#count ⇒ Object
22 23 24 |
# File 'lib/content_spinning/spinner.rb', line 22 def count map(&:count).inject(:+) end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/content_spinning/spinner.rb', line 26 def inspect "<Spinner {#{map(&:inspect).join(" | ")}}>" end |
#random ⇒ Object
30 31 32 |
# File 'lib/content_spinning/spinner.rb', line 30 def random sample.random end |
#spin ⇒ Object
34 35 36 |
# File 'lib/content_spinning/spinner.rb', line 34 def spin flat_map(&:spin) end |
#to_source ⇒ Object
38 39 40 |
# File 'lib/content_spinning/spinner.rb', line 38 def to_source "{#{map(&:to_source).join("|")}}" end |