Kouhei Sutou
null+****@clear*****
Sun Feb 19 00:08:53 JST 2017
Kouhei Sutou 2017-02-19 00:08:53 +0900 (Sun, 19 Feb 2017) New Revision: 38f21dfd38963faf1957f9c60b4c2afb8a05aca6 https://github.com/ranguba/chupa-text/commit/38f21dfd38963faf1957f9c60b4c2afb8a05aca6 Message: Data accepts source data Modified files: lib/chupa-text/data.rb lib/chupa-text/input-data.rb lib/chupa-text/text-data.rb lib/chupa-text/virtual-file-data.rb Modified: lib/chupa-text/data.rb (+22 -2) =================================================================== --- lib/chupa-text/data.rb 2017-02-18 01:05:52 +0900 (bbb3480) +++ lib/chupa-text/data.rb 2017-02-19 00:08:53 +0900 (5a473cc) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2017 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -51,7 +51,7 @@ module ChupaText # archive data in {#source}. attr_accessor :source - def initialize + def initialize(options={}) @uri = nil @body = nil @size = nil @@ -59,6 +59,9 @@ module ChupaText @mime_type = nil @attributes = Attributes.new @source = nil + @options = options || {} + source_data = @options[:source_data] + merge!(source_data) if source_data end def initialize_copy(object) @@ -67,6 +70,23 @@ module ChupaText self end + # Merges metadata from data. + # + # @param [Data] data The data to be merged. + # + # @return [void] + def merge!(data) + self.uri = data.uri + self.path = data.path + data.attributes.each do |name, value| + self[name] = value + end + if data.mime_type + self["original-mime-types"] ||= [] + self["original-mime-types"].unshift(data.mime_type) + end + end + # @param [String, URI, nil] uri The URI for the data. If `uri` is # `nil`, it means that the data isn't associated with any URIs. def uri=(uri) Modified: lib/chupa-text/input-data.rb (+3 -3) =================================================================== --- lib/chupa-text/input-data.rb 2017-02-18 01:05:52 +0900 (cc4fa13) +++ lib/chupa-text/input-data.rb 2017-02-19 00:08:53 +0900 (0967ab6) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2017 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -19,8 +19,8 @@ require "open-uri" module ChupaText class InputData < Data - def initialize(uri) - super() + def initialize(uri, options={}) + super(options) self.uri = uri if****@uri***** == URI::Generic @content = FileContent.new(@uri.path) Modified: lib/chupa-text/text-data.rb (+3 -3) =================================================================== --- lib/chupa-text/text-data.rb 2017-02-18 01:05:52 +0900 (1e806e9) +++ lib/chupa-text/text-data.rb 2017-02-19 00:08:53 +0900 (309005f) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2017 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -16,8 +16,8 @@ module ChupaText class TextData < Data - def initialize(text) - super() + def initialize(text, options={}) + super(options) self.mime_type = "text/plain" self.body = text self.size = text.bytesize Modified: lib/chupa-text/virtual-file-data.rb (+3 -3) =================================================================== --- lib/chupa-text/virtual-file-data.rb 2017-02-18 01:05:52 +0900 (64e2685) +++ lib/chupa-text/virtual-file-data.rb 2017-02-19 00:08:53 +0900 (d53017c) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2017 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -16,8 +16,8 @@ module ChupaText class VirtualFileData < Data - def initialize(uri, input) - super() + def initialize(uri, input, options={}) + super(options) self.uri = uri if @uri path =****@uri***** -------------- next part -------------- HTML����������������������������...下载