Class: GemDating::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_dating/input.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Input

Returns a new instance of Input.



13
14
15
# File 'lib/gem_dating/input.rb', line 13

def initialize(contents)
  @contents = contents
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



11
12
13
# File 'lib/gem_dating/input.rb', line 11

def contents
  @contents
end

Class Method Details

.file(path) ⇒ Object



7
8
9
# File 'lib/gem_dating/input.rb', line 7

def self.file(path)
  new(IO.read(path))
end

.string(s) ⇒ Object



3
4
5
# File 'lib/gem_dating/input.rb', line 3

def self.string(s)
  new(s)
end

Instance Method Details

#cleanup(line) ⇒ Object



38
39
40
41
42
# File 'lib/gem_dating/input.rb', line 38

def cleanup(line)
  # "foo",
  # 'hi'
  line.strip.chomp(",").chomp("'").chomp('"').delete_prefix("'").delete_prefix('"')
end

#gem_line(line) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gem_dating/input.rb', line 25

def gem_line(line)
  single_word_ruby_statements = %w{end else # gemspec}
  return if single_word_ruby_statements.include? line.strip

  if line.start_with? "gem("
    line.split("(")[1].split(",")[0]
  elsif line.start_with? "gem"
    line.split[1].split(",")[0]
  elsif line.split.length == 1 # match "just" gemname
    line
  end
end

#gemsObject



17
18
19
20
21
22
23
# File 'lib/gem_dating/input.rb', line 17

def gems
  lines = contents.split("\n")
  lines.each_with_object([]) do |line, gems|
    line = gem_line(line.strip)
    gems << cleanup(line) if line
  end.uniq
end