Class: Onboard::Finder
- Inherits:
-
Object
- Object
- Onboard::Finder
- Defined in:
- lib/onboard/find.rb
Instance Attribute Summary collapse
-
#haystack ⇒ Object
readonly
Returns the value of attribute haystack.
-
#needle ⇒ Object
readonly
Returns the value of attribute needle.
Instance Method Summary collapse
- #info_ext?(file) ⇒ Boolean
-
#initialize(needle, haystack) ⇒ Finder
constructor
A new instance of Finder.
- #locate ⇒ Object
- #version(file) ⇒ Object
Constructor Details
#initialize(needle, haystack) ⇒ Finder
Returns a new instance of Finder.
9 10 11 12 |
# File 'lib/onboard/find.rb', line 9 def initialize(needle, haystack) @needle = needle @haystack = haystack end |
Instance Attribute Details
#haystack ⇒ Object (readonly)
Returns the value of attribute haystack.
7 8 9 |
# File 'lib/onboard/find.rb', line 7 def haystack @haystack end |
#needle ⇒ Object (readonly)
Returns the value of attribute needle.
7 8 9 |
# File 'lib/onboard/find.rb', line 7 def needle @needle end |
Instance Method Details
#info_ext?(file) ⇒ Boolean
35 36 37 |
# File 'lib/onboard/find.rb', line 35 def info_ext?(file) File.extname(file) == '.info' end |
#locate ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/onboard/find.rb', line 14 def locate found = {} Find.find(haystack) do |e| if File.directory?(e) if needle.has_key?(File.basename(e)) Dir.entries(e).select do |f| file = "#{e}/#{f}" if File.file?(file) if self.info_ext?(file) if self.version(file).empty? == false found[e] = self.version(file) end end end end end end end return found end |
#version(file) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/onboard/find.rb', line 39 def version(file) File.open(file) do |g| g.each_line do |line| if line =~ /version/ return line.scan(/.*?"(.*?)".*$/)[0].nil? ? '' : line.scan(/.*?"(.*?)".*$/)[0] end end end end |