Class: GemfileSorter::Line::Gem
- Inherits:
-
Object
- Object
- GemfileSorter::Line::Gem
- Includes:
- Comparable
- Defined in:
- lib/gemfile_sorter/line/gem.rb
Instance Attribute Summary collapse
-
#comment_group ⇒ Object
Returns the value of attribute comment_group.
-
#group_extractor ⇒ Object
readonly
Returns the value of attribute group_extractor.
-
#line ⇒ Object
Returns the value of attribute line.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parsed ⇒ Object
Returns the value of attribute parsed.
-
#source_extractor ⇒ Object
readonly
Returns the value of attribute source_extractor.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #extract ⇒ Object
-
#initialize(name, comment_group = nil, *options, line: "", line_number: nil) ⇒ Gem
constructor
A new instance of Gem.
- #inline_kind ⇒ Object
- #inline_line ⇒ Object
- #inline_match ⇒ Object
- #inline_match? ⇒ Boolean
- #inline_result ⇒ Object
- #parsed_line ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, comment_group = nil, *options, line: "", line_number: nil) ⇒ Gem
Returns a new instance of Gem.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gemfile_sorter/line/gem.rb', line 8 def initialize(name, comment_group = nil, *, line: "", line_number: nil) @line = line.rstrip @name = name @options = @line_number = line_number @comment_group = comment_group || CommentGroup.new @group_extractor = GemExtractor.new(self, "group") @source_extractor = GemExtractor.new(self, "source") @parsed = false end |
Instance Attribute Details
#comment_group ⇒ Object
Returns the value of attribute comment_group.
6 7 8 |
# File 'lib/gemfile_sorter/line/gem.rb', line 6 def comment_group @comment_group end |
#group_extractor ⇒ Object (readonly)
Returns the value of attribute group_extractor.
5 6 7 |
# File 'lib/gemfile_sorter/line/gem.rb', line 5 def group_extractor @group_extractor end |
#line ⇒ Object
Returns the value of attribute line.
6 7 8 |
# File 'lib/gemfile_sorter/line/gem.rb', line 6 def line @line end |
#line_number ⇒ Object
Returns the value of attribute line_number.
6 7 8 |
# File 'lib/gemfile_sorter/line/gem.rb', line 6 def line_number @line_number end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/gemfile_sorter/line/gem.rb', line 6 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/gemfile_sorter/line/gem.rb', line 6 def @options end |
#parsed ⇒ Object
Returns the value of attribute parsed.
6 7 8 |
# File 'lib/gemfile_sorter/line/gem.rb', line 6 def parsed @parsed end |
#source_extractor ⇒ Object (readonly)
Returns the value of attribute source_extractor.
5 6 7 |
# File 'lib/gemfile_sorter/line/gem.rb', line 5 def source_extractor @source_extractor end |
Instance Method Details
#<=>(other) ⇒ Object
47 48 49 50 51 |
# File 'lib/gemfile_sorter/line/gem.rb', line 47 def <=>(other) name <=> other.name rescue raise InvalidLineComparisonError end |
#extract ⇒ Object
36 37 38 39 |
# File 'lib/gemfile_sorter/line/gem.rb', line 36 def extract self.parsed = true group_extractor.extract || source_extractor.extract end |
#inline_kind ⇒ Object
41 |
# File 'lib/gemfile_sorter/line/gem.rb', line 41 def inline_kind = inline_match&.key |
#inline_line ⇒ Object
45 |
# File 'lib/gemfile_sorter/line/gem.rb', line 45 def inline_line = inline_match.resulting_first_line |
#inline_match ⇒ Object
28 29 30 31 32 |
# File 'lib/gemfile_sorter/line/gem.rb', line 28 def inline_match extract unless parsed [group_extractor, source_extractor] .find { _1.match? } end |
#inline_match? ⇒ Boolean
34 |
# File 'lib/gemfile_sorter/line/gem.rb', line 34 def inline_match? = !!inline_match |
#inline_result ⇒ Object
43 |
# File 'lib/gemfile_sorter/line/gem.rb', line 43 def inline_result = inline_match&.result_string |
#parsed_line ⇒ Object
23 24 25 26 |
# File 'lib/gemfile_sorter/line/gem.rb', line 23 def parsed_line return line unless inline_match? inline_match.updated_line end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/gemfile_sorter/line/gem.rb', line 19 def to_s (comment_group.empty? ? "" : "\n") + comment_group.to_s + parsed_line + "\n" end |