Class: GemBench::Player
- Inherits:
-
Object
- Object
- GemBench::Player
- Defined in:
- lib/gem_bench/player.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #careful(num) ⇒ Object
-
#gemfile_regex ⇒ Object
Used to find the line of the Gemfile which creates the primary dependency on this gem.
- #how ⇒ Object
-
#initialize(options = {}) ⇒ Player
constructor
A new instance of Player.
- #path_glob ⇒ Object
- #set_starter(file_path) ⇒ Object
- #starter? ⇒ Boolean
- #suggest(num) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Player
Returns a new instance of Player.
6 7 8 9 10 11 |
# File 'lib/gem_bench/player.rb', line 6 def initialize( = {}) @name = [:name] @version = [:version] @state = nil @stats = [] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/gem_bench/player.rb', line 4 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/gem_bench/player.rb', line 4 def state @state end |
#stats ⇒ Object
Returns the value of attribute stats.
4 5 6 |
# File 'lib/gem_bench/player.rb', line 4 def stats @stats end |
#version ⇒ Object
Returns the value of attribute version.
4 5 6 |
# File 'lib/gem_bench/player.rb', line 4 def version @version end |
Instance Method Details
#careful(num) ⇒ Object
56 57 58 |
# File 'lib/gem_bench/player.rb', line 56 def careful(num) "\t[BE CAREFUL] #{num}) #{self.how}" end |
#gemfile_regex ⇒ Object
Used to find the line of the Gemfile which creates the primary dependency on this gem
36 37 38 |
# File 'lib/gem_bench/player.rb', line 36 def gemfile_regex GemBench::DEPENDENCY_REGEX.call(self.name) end |
#how ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/gem_bench/player.rb', line 44 def how case self.state when GemBench::PLAYER_STATES[:starter] then "gem '#{self.name}', '~> #{self.version}'" when GemBench::PLAYER_STATES[:bench] then "gem '#{self.name}', '~> #{self.version}', require: false" else "#{self} is feeling very lost right now." end end |
#path_glob ⇒ Object
13 14 15 |
# File 'lib/gem_bench/player.rb', line 13 def path_glob GemBench::PATH_GLOB.call(self.name) end |
#set_starter(file_path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gem_bench/player.rb', line 17 def set_starter(file_path) scan = begin if GemBench::DO_NOT_SCAN.include? self.name false else File.read(file_path).encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_') =~ GemBench::RAILTIE_REGEX end end self.stats << [file_path,scan] if scan self.state = !!scan ? GemBench::PLAYER_STATES[:starter] : GemBench::PLAYER_STATES[:bench] end |
#starter? ⇒ Boolean
31 32 33 |
# File 'lib/gem_bench/player.rb', line 31 def starter? self.state == GemBench::PLAYER_STATES[:starter] end |
#suggest(num) ⇒ Object
52 53 54 |
# File 'lib/gem_bench/player.rb', line 52 def suggest(num) "\t[SUGGESTION] #{num}) #{self.how}" end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/gem_bench/player.rb', line 40 def to_s "#{self.name} v#{self.version}" end |