Class: Fontist::Import::Otf::FontFile
- Inherits:
-
Object
- Object
- Fontist::Import::Otf::FontFile
- Defined in:
- lib/fontist/import/otf/font_file.rb
Constant Summary collapse
- REQUIREMENTS =
{ otfinfo: Otfinfo::OtfinfoRequirement.new, }.freeze
- STYLE_ATTRIBUTES =
i[family_name type preferred_family_name preferred_type full_name post_script_name version description copyright font source_font].freeze
- COLLECTION_ATTRIBUTES =
STYLE_ATTRIBUTES.reject do |a| i[font source_font].include?(a) end
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #copyright ⇒ Object
- #description ⇒ Object
- #family_name ⇒ Object
- #font ⇒ Object
- #full_name ⇒ Object
- #homepage ⇒ Object
-
#initialize(path, name_prefix: nil) ⇒ FontFile
constructor
A new instance of FontFile.
- #license_url ⇒ Object
- #post_script_name ⇒ Object
- #preferred_family_name ⇒ Object
- #preferred_type ⇒ Object
- #source_font ⇒ Object
- #to_collection_style ⇒ Object
- #to_style ⇒ Object
- #type ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path, name_prefix: nil) ⇒ FontFile
Returns a new instance of FontFile.
24 25 26 27 28 29 |
# File 'lib/fontist/import/otf/font_file.rb', line 24 def initialize(path, name_prefix: nil) @path = path @name_prefix = name_prefix @info = read @extension = detect_extension end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/fontist/import/otf/font_file.rb', line 22 def path @path end |
Instance Method Details
#copyright ⇒ Object
87 88 89 |
# File 'lib/fontist/import/otf/font_file.rb', line 87 def copyright info["Copyright"] end |
#description ⇒ Object
73 74 75 |
# File 'lib/fontist/import/otf/font_file.rb', line 73 def description info["Description"] end |
#family_name ⇒ Object
39 40 41 42 |
# File 'lib/fontist/import/otf/font_file.rb', line 39 def family_name name = info["Family"] @name_prefix ? "#{@name_prefix}#{name}" : name end |
#font ⇒ Object
77 78 79 80 81 |
# File 'lib/fontist/import/otf/font_file.rb', line 77 def font basename = File.basename(@path, ".*").chomp(".#{@extension}") "#{basename}.#{@extension}" end |
#full_name ⇒ Object
59 60 61 |
# File 'lib/fontist/import/otf/font_file.rb', line 59 def full_name info["Full name"] end |
#homepage ⇒ Object
91 92 93 |
# File 'lib/fontist/import/otf/font_file.rb', line 91 def homepage info["Vendor URL"] end |
#license_url ⇒ Object
95 96 97 |
# File 'lib/fontist/import/otf/font_file.rb', line 95 def license_url info["License URL"] end |
#post_script_name ⇒ Object
63 64 65 |
# File 'lib/fontist/import/otf/font_file.rb', line 63 def post_script_name info["PostScript name"] end |
#preferred_family_name ⇒ Object
48 49 50 51 52 53 |
# File 'lib/fontist/import/otf/font_file.rb', line 48 def preferred_family_name name = info["Preferred family"] return unless name @name_prefix ? "#{@name_prefix}#{name}" : name end |
#preferred_type ⇒ Object
55 56 57 |
# File 'lib/fontist/import/otf/font_file.rb', line 55 def preferred_type info["Preferred subfamily"] end |
#source_font ⇒ Object
83 84 85 |
# File 'lib/fontist/import/otf/font_file.rb', line 83 def source_font File.basename(@path) unless font == File.basename(@path) end |
#to_collection_style ⇒ Object
35 36 37 |
# File 'lib/fontist/import/otf/font_file.rb', line 35 def to_collection_style COLLECTION_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact end |
#to_style ⇒ Object
31 32 33 |
# File 'lib/fontist/import/otf/font_file.rb', line 31 def to_style STYLE_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact end |
#type ⇒ Object
44 45 46 |
# File 'lib/fontist/import/otf/font_file.rb', line 44 def type info["Subfamily"] end |
#version ⇒ Object
67 68 69 70 71 |
# File 'lib/fontist/import/otf/font_file.rb', line 67 def version return unless info["Version"] info["Version"].gsub("Version ", "") end |