lib/sub_diff/builder.rb in sub_diff-1.0.2 vs lib/sub_diff/builder.rb in sub_diff-1.0.3

- old
+ new

@@ -1,9 +1,15 @@ module SubDiff - class Builder < Struct.new(:string, :type) + class Builder + def initialize(string, type) + @string = string + @type = type + end + def diff(*args, &block) - builder.diff(*args, &block) + @collection = Collection.new(string) + adapter.diff(*args, &block) collection end def push(*args) if args.compact.any? @@ -13,26 +19,24 @@ end alias_method :<<, :push private - def builder - constant.new(differ) + attr_reader :collection, :string, :type + + def adapter + adapter_class.new(differ) end - def constant - Module.nesting.last.const_get(constant_name) + def adapter_class + Module.nesting.last.const_get(adapter_name) end - def constant_name + def adapter_name type.to_s.capitalize end def differ Differ.new(self, type) - end - - def collection - @collection ||= Collection.new(string) end end end