class Apropos::Set
A Set
generates a list of Variants from a base image path. Any file in the same directory as the base image with the pattern “basename.*.extension” is considered to be a potential Variant
, though not all generated Variants are guaranteed to be valid.
Attributes
path[R]
Public Class Methods
glob(path)
click to toggle source
Wrapper for Dir.glob to make test stubbing cleaner
# File lib/apropos/set.rb, line 71 def self.glob(path) Dir.glob(path) end
new(path, basedir)
click to toggle source
# File lib/apropos/set.rb, line 9 def initialize(path, basedir) @path = path @basedir = Pathname.new(basedir) end
Public Instance Methods
basedir_re()
click to toggle source
# File lib/apropos/set.rb, line 45 def basedir_re @basedir_re ||= Regexp.new("^.*#{Regexp.escape(@basedir.to_s)}/") end
basename()
click to toggle source
# File lib/apropos/set.rb, line 62 def basename @basename ||= File.basename(@path, extname) end
code_fragment(path)
click to toggle source
# File lib/apropos/set.rb, line 49 def code_fragment(path) start = File.join(File.dirname(path), basename) path[(start.length + 1)...(path.length - extname.length)] end
dirname()
click to toggle source
# File lib/apropos/set.rb, line 58 def dirname @dirname ||= File.dirname(@path) end
extname()
click to toggle source
# File lib/apropos/set.rb, line 66 def extname @extname ||= File.extname(@path) end
invalid_variants()
click to toggle source
# File lib/apropos/set.rb, line 24 def invalid_variants variants.reject(&:valid?) end
remove_basedir(path)
click to toggle source
# File lib/apropos/set.rb, line 41 def remove_basedir(path) path.sub(basedir_re, '') end
valid_variant_rules()
click to toggle source
# File lib/apropos/set.rb, line 28 def valid_variant_rules valid_variants.map(&:rule) end
valid_variants()
click to toggle source
# File lib/apropos/set.rb, line 20 def valid_variants variants.select(&:valid?) end
variant_path_glob()
click to toggle source
# File lib/apropos/set.rb, line 54 def variant_path_glob Pathname.new(dirname).join("#{basename}#{SEPARATOR}*#{extname}") end
variant_paths()
click to toggle source
# File lib/apropos/set.rb, line 32 def variant_paths paths = {} self.class.glob(@basedir.join(variant_path_glob)).each do |path| key = code_fragment(path) paths[key] = remove_basedir(path) end paths end
variants()
click to toggle source
# File lib/apropos/set.rb, line 14 def variants variant_paths.map do |code_fragment, path| Variant.new(code_fragment, path) end.sort end