rubyhexagon 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1920d433c32360d24b4091fa37a7132f9fac4ccf36b400e034b2491679bee5b0
4
- data.tar.gz: 7abdf32fcfaf560525b03697b7c68e63faff335bb6677c3569631b6d6b71b69e
3
+ metadata.gz: f3b33b5997c2add67eddbfeea3016cc29e5699996b7dc38a2653ed692bbdeb0f
4
+ data.tar.gz: d5df5106fef14164a6e33ce3e0b35a80836b2902b299cbc53d574944f32894f6
5
5
  SHA512:
6
- metadata.gz: 8a682ee7cba26e33eed44ddc234d41ea8ea31fd8e1dc06d9838ad2096aecc0fb97bcd47721dfb4731181ee02f675c283d4948a98a73957636239d8a1b5b639b5
7
- data.tar.gz: 23b285239417e638de6b8873d8023b0840cb2039fb778382f367d7c9e8542da653737ea002108307fc9bfcbf6dd0790d72fc5b387ab62e6365e2aa4eeb73000c
6
+ metadata.gz: a9abec7cf7b10ac58e7c11cf6ad5fb7ed660af4c29153d2cab8082d738345d1f5cc67004d2c3ccc7bf196089a157f0a7f2370f7508309b65a2223df0bb2cfd5b
7
+ data.tar.gz: ff325c1d8f244e1ddf40eea8590fa339f5007f848033feb73ef18fe82fe0a5b95db11df3cde327ef2f5583d273eff354707a437e8a2b7d9500ed58f2cb041f89
@@ -36,6 +36,9 @@ require 'rubyhexagon/search/tags'
36
36
  # @author Maxine Michalski
37
37
  # @since 0.4.3
38
38
  module E621
39
+ MAJOR = 1
40
+ MINOR = 1
41
+ PATCH = 0
39
42
  NAME = 'rubyhexagon'.freeze
40
- VERSION = '1.0.0'.freeze
43
+ VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
41
44
  end
@@ -70,12 +70,15 @@ module E621
70
70
  #
71
71
  # @param dirname [String] path where to save. This needs be an existing
72
72
  # directory. This overwrites existing files.
73
+ # @param filename [String] name of file, without extension
74
+ #
73
75
  # @raise [ArgumentError] Argument given is not an existing directory
74
- def save!(dirname = './')
76
+ def save!(dirname = './', filename = nil)
75
77
  raise ArgumentError, 'Not a directory!' unless File.directory?(dirname)
78
+ filename ||= @md5
76
79
  loop do
77
80
  stream = open(@url, @user_agent).read
78
- File.open("#{dirname}/#{File.basename(@url.path)}", 'w') do |f|
81
+ File.open("#{dirname}/#{filename}.#{@ext}", 'w') do |f|
79
82
  f.print stream
80
83
  end
81
84
  break if Digest::MD5.hexdigest(stream) == @md5
@@ -74,6 +74,9 @@ module E621
74
74
  # @return [E621::Preview] preview data in E621::Preview format
75
75
  attr_reader :preview
76
76
 
77
+ # @return [Array<String>] tag names only for convenience
78
+ attr_reader :tag_names
79
+
77
80
  # @author Maxine Michalski
78
81
  #
79
82
  # Initializer for Post.
@@ -132,31 +135,22 @@ module E621
132
135
  # Test status with an optional parameter. This is more meant to be used by
133
136
  # alias methods
134
137
  #
135
- # @return [TrueClass]
136
- # @return [FalseClass]
137
- def test_status(status = nil)
138
- status ||= __callee__.to_s.sub(/\?/, '').to_sym
139
- @status == status
140
- end
141
- alias active? test_status
142
- alias flagged? test_status
143
- alias pending? test_status
144
- alias deleted? test_status
145
-
146
- # @author Maxine Michalski
147
- #
148
- # Check a post for a certain rating. This is rather meant to be used via
149
- # alias methids.
138
+ # @param test_var [Symbol] variable under test
150
139
  #
151
140
  # @return [TrueClass]
152
141
  # @return [FalseClass]
153
- def test_rating(rating = nil)
154
- rating ||= __callee__.to_s.sub(/\?/, '').to_sym
155
- @rating == rating
142
+ def test(test_var = nil)
143
+ test_var ||= __callee__.to_s.sub(/\?/, '').to_sym
144
+ test_ar = %i[safe questionable explicit]
145
+ test_ar.include?(test_var) ? @rating == test_var : @status == test_var
156
146
  end
157
- alias safe? test_rating
158
- alias questionable? test_rating
159
- alias explicit? test_rating
147
+ alias active? test
148
+ alias flagged? test
149
+ alias pending? test
150
+ alias deleted? test
151
+ alias safe? test
152
+ alias questionable? test
153
+ alias explicit? test
160
154
 
161
155
  # @author Maxine Michalski
162
156
  #
@@ -173,6 +167,7 @@ module E621
173
167
  #
174
168
  # Helper function, to setup post file data
175
169
  def setup_file_data(post)
170
+ @tag_names = post[:tags].split(/\s+/)
176
171
  @md5 = post[:md5]
177
172
  @image = E621::Image.new(url: post[:file_url], ext: post[:file_ext],
178
173
  width: post[:width], height: post[:height])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyhexagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxine Michalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-25 00:00:00.000000000 Z
11
+ date: 2018-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json