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

- old
+ new

@@ -1,55 +1,34 @@ require "cheapredwine/version" -require "cheapredwine/info" -require "cheapredwine/image" +require "cheapredwine/command" -class CheapRedWine +class Cheapredwine extend Forwardable - attr_accessor :font - def_delegators :@font, :file, :name, :family, :style, :features - 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 + attr_accessor :file + def_delegators :@attrs, :font_name, :family_name, :style, :features + + def initialize file + @attrs = Parser.new file + @file = File.new file end - def image(text, options = {}) - features = merge_features(font.features, options.fetch(:features) { [] }) - - params = options.merge({ - features: features, - font: font.file, - text: text - }) + def image &block + create(&block).run! + end - params = Image::Params.new(params) - Image::Writer.new(params).exec + def create &block + builder.instance_eval &block + builder.font_file file.path + runner end private - def merge_features(all_features, selected_features) - all_features.map do |feature| - prefix = selected_features.include?(feature) ? '+' : '-' - prefix + feature - end + def builder + @builder ||= Command::Builder.new end - class Font - attr_accessor :name, :family, :features, :path, :style - - def initialize - yield(self) if block_given? - end - - def file - File.new(path) - end + def runner + @runner ||= Command::Runner.new builder end end