Class: Fontist::Import::Otf::FontFile

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FontFile

Returns a new instance of FontFile.



24
25
26
27
28
# File 'lib/fontist/import/otf/font_file.rb', line 24

def initialize(path)
  @path = path
  @info = read
  @extension = detect_extension
end

Instance Attribute Details

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



82
83
84
# File 'lib/fontist/import/otf/font_file.rb', line 82

def copyright
  info["Copyright"]
end

#descriptionObject



68
69
70
# File 'lib/fontist/import/otf/font_file.rb', line 68

def description
  info["Description"]
end

#family_nameObject



38
39
40
# File 'lib/fontist/import/otf/font_file.rb', line 38

def family_name
  info["Family"]
end

#fontObject



72
73
74
75
76
# File 'lib/fontist/import/otf/font_file.rb', line 72

def font
  basename = File.basename(@path, ".*").chomp(".#{@extension}")

  "#{basename}.#{@extension}"
end

#full_nameObject



54
55
56
# File 'lib/fontist/import/otf/font_file.rb', line 54

def full_name
  info["Full name"]
end

#homepageObject



86
87
88
# File 'lib/fontist/import/otf/font_file.rb', line 86

def homepage
  info["Vendor URL"]
end

#license_urlObject



90
91
92
# File 'lib/fontist/import/otf/font_file.rb', line 90

def license_url
  info["License URL"]
end

#post_script_nameObject



58
59
60
# File 'lib/fontist/import/otf/font_file.rb', line 58

def post_script_name
  info["PostScript name"]
end

#preferred_family_nameObject



46
47
48
# File 'lib/fontist/import/otf/font_file.rb', line 46

def preferred_family_name
  info["Preferred family"]
end

#preferred_typeObject



50
51
52
# File 'lib/fontist/import/otf/font_file.rb', line 50

def preferred_type
  info["Preferred subfamily"]
end

#source_fontObject



78
79
80
# File 'lib/fontist/import/otf/font_file.rb', line 78

def source_font
  File.basename(@path) unless font == File.basename(@path)
end

#to_collection_styleObject



34
35
36
# File 'lib/fontist/import/otf/font_file.rb', line 34

def to_collection_style
  COLLECTION_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
end

#to_styleObject



30
31
32
# File 'lib/fontist/import/otf/font_file.rb', line 30

def to_style
  STYLE_ATTRIBUTES.map { |name| [name, send(name)] }.to_h.compact
end

#typeObject



42
43
44
# File 'lib/fontist/import/otf/font_file.rb', line 42

def type
  info["Subfamily"]
end

#versionObject



62
63
64
65
66
# File 'lib/fontist/import/otf/font_file.rb', line 62

def version
  return unless info["Version"]

  info["Version"].gsub("Version ", "")
end