Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth committed Sep 3, 2014
1 parent 122c5a8 commit 49359a2
Showing 1 changed file with 25 additions and 49 deletions.
74 changes: 25 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,76 +39,52 @@ Or install it yourself as:

Currently requires `RUBY_VERSION >= 1.9.3`.

## Example Usage
## Usage

### Documentation
Full API documentation is available via YARD or here:
http://rubydoc.info/github/mroth/emoji_data.rb/master/frames

Pretty straightforward, read the source. But here are some things you might
care about:

### EmojiData

The `EmojiData` module provides some convenience methods for dealing with the
library of known emoji characters. Check out the source to see what's up.

Some notable methods to call out:

`EmojiData.from_unified(id)` gives you a quick way to grab a specific `EmojiChar`.
### Examples
Here are some examples of the type of stuff you can do:

```irb
>> require 'emoji_data'
=> true
>> EmojiData.from_unified('1f680')
=> #<EmojiData::EmojiChar:0x007f8fdba33b40 @variations=[], @name="ROCKET",
@unified="1F680", @docomo=nil, @au="E5C8", @softbank="E10D", @google="FE7ED",
@image="1f680.png", @sheet_x=25, @sheet_y=4, @short_name="rocket",
@short_names=["rocket"], @text=nil, @apple_img=true, @hangouts_img=true,
@twitter_img=true>
```

`EmojiData.find_by_name(name)` and `.find_by_short_name(name)` do pretty much
what you'd expect:

```irb
>> EmojiData.find_by_name('thumb')
=> [#<EmojiData::EmojiChar:0x007f8fdb939780 @variations=[], @name="THUMBS UP
SIGN", @unified="1F44D", @docomo="E727", @au="E4F9", @softbank="E00E",
@google="FEB97", @image="1f44d.png", @sheet_x=13, @sheet_y=22, @short_name="+1",
@short_names=["+1", "thumbsup"], @text=nil, @apple_img=true, @hangouts_img=true,
@twitter_img=true>, #<EmojiData::EmojiChar:0x007f8fdb933510 @variations=[],
@name="THUMBS DOWN SIGN", @unified="1F44E", @docomo="E700", @au="EAD5",
@softbank="E421", @google="FEBA0", @image="1f44e.png", @sheet_x=13, @sheet_y=23,
@short_name="-1", @short_names=["-1", "thumbsdown"], @text=nil, @apple_img=true,
@hangouts_img=true, @twitter_img=true>]
```
`EmojiData.char_to_unified(char)` takes a string containing a unified unicode
representation of an emoji character and gives you the unicode ID.
>> EmojiData.all.count
=> 845
```irb
>> EmojiData.char_to_unified('🚀')
=> "1F680"
```
>> EmojiData.all_with_variants.count
=> 107
`EmojiData.all` will return an array of all known EmojiChars, so you can map
or do whatever funky Enumerable stuff you want to do across the entire
character set.
>> EmojiData.find_by_short_name("moon").count
=> 13
```irb
#gimmie the shortname of all doublebyte chars
>> EmojiData.all.select(&:doublebyte?).map(&:short_name)
=> ["hash", "zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "cn", "de", "es", "fr", "gb", "it", "jp", "kr", "ru", "us"]
```
### EmojiData::EmojiChar

`EmojiData::EmojiChar` is a class representing a single emoji character. All
the variables from the `iamcal/emoji-data` dataset have dynamically generated
getter methods.
>> EmojiData.find_by_name("tree").map { |c| [c.unified, c.name, c.render] }
=> [["1F332", "EVERGREEN TREE", "🌲"], ["1F333", "DECIDUOUS TREE", "🌳"],
["1F334", "PALM TREE", "🌴"], ["1F384", "CHRISTMAS TREE", "🎄"], ["1F38B",
"TANABATA TREE", "🎋"]]
>> EmojiData.scan("I ♥ when marketers talk about the ☁. #blessed").each do |ec|
?> puts "Found some #{ec.short_name}!"
>> end
Found some hearts!
Found some cloud!
=> [...]
```

There are some additional convenience methods, such as `#doublebyte?` etc. Most
important addition is the `#render` method which will output a properly unicode
encoded string containing the character.

## License

Expand Down

0 comments on commit 49359a2

Please sign in to comment.