Class: Fontist::Import::Google::MetadataParser
- Inherits:
-
Object
- Object
- Fontist::Import::Google::MetadataParser
- Defined in:
- lib/fontist/import/google/metadata_parser.rb
Overview
Parser for Google Fonts METADATA.pb files
Parses protobuf text format files and provides OO access to metadata
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#date_added ⇒ Object
readonly
Returns the value of attribute date_added.
-
#designer ⇒ Object
readonly
Returns the value of attribute designer.
-
#font_files ⇒ Object
readonly
Returns the value of attribute font_files.
-
#license ⇒ Object
readonly
Returns the value of attribute license.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#filenames ⇒ Array<String>
Returns array of font filenames.
-
#initialize(file_path_or_content) ⇒ MetadataParser
constructor
A new instance of MetadataParser.
-
#to_h ⇒ Hash
Returns hash representation.
Constructor Details
#initialize(file_path_or_content) ⇒ MetadataParser
Returns a new instance of MetadataParser.
18 19 20 21 22 23 24 25 26 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 18 def initialize(file_path_or_content) @content = if File.exist?(file_path_or_content.to_s) File.read(file_path_or_content, encoding: "UTF-8") else file_path_or_content end parse end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
15 16 17 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 15 def category @category end |
#date_added ⇒ Object (readonly)
Returns the value of attribute date_added.
15 16 17 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 15 def date_added @date_added end |
#designer ⇒ Object (readonly)
Returns the value of attribute designer.
15 16 17 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 15 def designer @designer end |
#font_files ⇒ Object (readonly)
Returns the value of attribute font_files.
15 16 17 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 15 def font_files @font_files end |
#license ⇒ Object (readonly)
Returns the value of attribute license.
15 16 17 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 15 def license @license end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 15 def name @name end |
Instance Method Details
#filenames ⇒ Array<String>
Returns array of font filenames
31 32 33 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 31 def filenames @font_files.map { |f| f[:filename] } end |
#to_h ⇒ Hash
Returns hash representation
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fontist/import/google/metadata_parser.rb', line 38 def to_h { name: @name, designer: @designer, license: @license, category: @category, date_added: @date_added, font_files: @font_files, } end |