Class: Fontist::Import::Google::MetadataParser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#categoryObject (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_addedObject (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

#designerObject (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_filesObject (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

#licenseObject (readonly)

Returns the value of attribute license.



15
16
17
# File 'lib/fontist/import/google/metadata_parser.rb', line 15

def license
  @license
end

#nameObject (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

#filenamesArray<String>

Returns array of font filenames

Returns:

  • (Array<String>)

    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_hHash

Returns hash representation

Returns:

  • (Hash)

    metadata hash



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