Method: Pixiv::Client#filename_from_pattern

Defined in:
lib/pixiv/client.rb

#filename_from_pattern(pattern, illust, url) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generate filename from pattern in context of illust and url

The pattern is an array of string, symbol, or object that responds to #call. Each component of the pattern is replaced by the following rules and then the pattern is concatenated as the returning filename.

  • :image_name in the pattern is replaced with the base name of the url

  • Any other symbol is replaced with the value of illust.send(the_symbol)

  • #call-able object is replaced with the value of the_object.call(illust)

  • String is left as-is

Parameters:

  • pattern (Array<String, Symbol, #call>)
  • illust (Pixiv::Illust)
  • url (String)

Returns:

  • (String)

    filename



194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/pixiv/client.rb', line 194

def filename_from_pattern(pattern, illust, url)
  pattern.map {|i|
    if i == :image_name
      name = File.basename(url)
      if name =~ /\.(\w+)\?\d+$/
        name += '.' + $1
      end
      name
    elsif i.is_a?(Symbol) then illust.send(i)
    elsif i.respond_to?(:call) then i.call(illust)
    else i
    end
  }.join('')
end