Class: Himg::CLI::Document
- Inherits:
-
Object
- Object
- Himg::CLI::Document
- Defined in:
- lib/himg/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source, options) ⇒ Document
constructor
A new instance of Document.
- #load(&block) ⇒ Object
- #stdin? ⇒ Boolean
Constructor Details
#initialize(source, options) ⇒ Document
Returns a new instance of Document.
98 99 100 101 102 |
# File 'lib/himg/cli.rb', line 98 def initialize(source, ) @source = source = @http_headers = [:http_headers] end |
Class Method Details
.http_url?(url) ⇒ Boolean
104 105 106 |
# File 'lib/himg/cli.rb', line 104 def self.http_url?(url) url.to_s =~ %r{\Ahttps?\://} end |
Instance Method Details
#load(&block) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/himg/cli.rb', line 112 def load(&block) if stdin? yield($stdin.read) elsif self.class.http_url?(@source) args = [@source] args << @http_headers if @http_headers URI.open(*args) do |input| yield(input.binmode.read) end else File.open(@source) do |f| yield(f.read) end end end |
#stdin? ⇒ Boolean
108 109 110 |
# File 'lib/himg/cli.rb', line 108 def stdin? @source.nil? end |