Class: EmojiDiffer::List
- Inherits:
-
Object
- Object
- EmojiDiffer::List
- Includes:
- Enumerable
- Defined in:
- lib/emoji_differ/list.rb
Class Method Summary collapse
Instance Method Summary collapse
- #-(other) ⇒ Object
- #each ⇒ Object
- #emojis ⇒ Object
-
#initialize(emoji = nil) ⇒ List
constructor
A new instance of List.
- #length ⇒ Object
- #parse(json) ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(emoji = nil) ⇒ List
Returns a new instance of List.
8 9 10 |
# File 'lib/emoji_differ/list.rb', line 8 def initialize(emoji=nil) @emojis = emoji end |
Class Method Details
.from_json(json) ⇒ Object
12 13 14 |
# File 'lib/emoji_differ/list.rb', line 12 def self.from_json(json) new.parse(json) end |
Instance Method Details
#-(other) ⇒ Object
27 28 29 30 |
# File 'lib/emoji_differ/list.rb', line 27 def -(other) other_names = other.emojis.to_a.map(&:name) self.class.new(emojis.reject {|emoji| other_names.include?(emoji.name) }) end |
#each ⇒ Object
21 22 23 24 25 |
# File 'lib/emoji_differ/list.rb', line 21 def each emojis.each do |emoji| yield emoji end end |
#emojis ⇒ Object
40 41 42 |
# File 'lib/emoji_differ/list.rb', line 40 def emojis @emojis ||= transform end |
#length ⇒ Object
32 33 34 |
# File 'lib/emoji_differ/list.rb', line 32 def length emojis.length end |
#parse(json) ⇒ Object
44 45 46 47 |
# File 'lib/emoji_differ/list.rb', line 44 def parse(json) @parsed = JSON.parse(json) self end |
#to_json ⇒ Object
36 37 38 |
# File 'lib/emoji_differ/list.rb', line 36 def to_json JSON.generate(parsed) #cheeky eh end |
#to_s ⇒ Object
16 17 18 19 |
# File 'lib/emoji_differ/list.rb', line 16 def to_s collection = emojis.map(&:to_s).join(" ") "#{collection}\n Total: #{length}" end |