Class: TanukiEmoji::Db::EmojiDataParser
- Inherits:
-
Object
- Object
- TanukiEmoji::Db::EmojiDataParser
- Defined in:
- lib/tanuki_emoji/db/emoji_data_parser.rb
Overview
Reads and extract content from emoji-data.txt and its metadata
Constant Summary collapse
- DATA_FILE =
"#{::TanukiEmoji::Db::UNICODE_DATA_DIR}/emoji-data.txt".freeze
- PROPERTIES =
{ 'Emoji' => :emoji, 'Emoji_Presentation' => :emoji_presentation, 'Emoji_Modifier' => :emoji_modifier, 'Emoji_Modifier_Base' => :emoji_modifier_base, 'Emoji_Component' => :emoji_component, 'Extended_Pictographic' => :extended_pictographic }.freeze
Instance Attribute Summary collapse
-
#data_file ⇒ Object
readonly
Returns the value of attribute data_file.
Class Method Summary collapse
-
.data_file ⇒ Pathname
Return the path to the default data file (emoji-data.txt).
Instance Method Summary collapse
-
#data ⇒ Array<EmojiData>
Return the parsed data from the data file.
-
#initialize(data_file = self.class.data_file) ⇒ EmojiDataParser
constructor
A new instance of EmojiDataParser.
- #metadata ⇒ Object
- #raw_data ⇒ Object
Constructor Details
#initialize(data_file = self.class.data_file) ⇒ EmojiDataParser
Returns a new instance of EmojiDataParser.
30 31 32 |
# File 'lib/tanuki_emoji/db/emoji_data_parser.rb', line 30 def initialize(data_file = self.class.data_file) @data_file = data_file end |
Instance Attribute Details
#data_file ⇒ Object (readonly)
Returns the value of attribute data_file.
28 29 30 |
# File 'lib/tanuki_emoji/db/emoji_data_parser.rb', line 28 def data_file @data_file end |
Class Method Details
.data_file ⇒ Pathname
Return the path to the default data file (emoji-data.txt)
24 25 26 |
# File 'lib/tanuki_emoji/db/emoji_data_parser.rb', line 24 def self.data_file Pathname.new(File.(File.join(__dir__, '../../../', DATA_FILE))) end |
Instance Method Details
#data ⇒ Array<EmojiData>
Return the parsed data from the data file
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tanuki_emoji/db/emoji_data_parser.rb', line 37 def data parsed = [] load do |line| parse_data(line).tap do |result| parsed << result unless result.nil? end end parsed end |
#metadata ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tanuki_emoji/db/emoji_data_parser.rb', line 57 def parsed = [] load do |line| (line).tap do |result| parsed << result unless result.nil? end end = {} # Extract date raw_datetime = parsed.detect { |data| data[:key] == "Date" }&.fetch(:value) [:date] = DateTime.parse(raw_datetime) # Extract version [:version] = parsed.detect { |data| data[:key] == "Version" }&.fetch(:value) # Extract total elements [:total_elements] = parsed.select { |data| data[:key] == "Total elements" }.sum { |data| data[:value].to_i } end |
#raw_data ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/tanuki_emoji/db/emoji_data_parser.rb', line 48 def raw_data lines = [] load do |line| lines << line end lines end |