lib/cheapredwine.rb in cheapredwine-0.2.0 vs lib/cheapredwine.rb in cheapredwine-0.3.1

- old
+ new

@@ -1,57 +1,55 @@ require "cheapredwine/version" require "cheapredwine/info" require "cheapredwine/image" +class CheapRedWine + extend Forwardable + attr_accessor :font + def_delegators :@font, :file, :name, :family, :style, :features -module CheapRedWine - class Meta - attr_accessor :name, :family, :features, :path, :style - - def initialize - yield(self) if block_given? + def initialize(file) + info = Info.new file + @font = Font.new do |font| + font.name = info.font_name + font.family = info.family_name + font.features = info.features + font.style = info.style + font.path = file + font end - - def file - File.new(path) - end end - def self.meta(file) - parser = Info.new file - Meta.new do |meta| - meta.name = parser.font_name - meta.family = parser.family_name - meta.features = parser.features - meta.style = parser.style - meta.path = file - end - end - - def self.image(font, text, options = {}) + def image(text, options = {}) features = merge_features(font.features, options.fetch(:features) { [] }) - options.merge!({ + + params = options.merge({ features: features, font: font.file, text: text }) - params = Image::Params.new(options) + + params = Image::Params.new(params) Image::Writer.new(params).exec end - def self.ttx_output_folder=(folder) - CheapRedWine::TTX.configuration.output_folder = folder - end - - def self.ttx_output_folder - CheapRedWine::TTX.configuration.output_folder - end - private - def self.merge_features(all_features, selected_features) + def merge_features(all_features, selected_features) all_features.map do |feature| prefix = selected_features.include?(feature) ? '+' : '-' prefix + feature + end + end + + class Font + attr_accessor :name, :family, :features, :path, :style + + def initialize + yield(self) if block_given? + end + + def file + File.new(path) end end end