Sha256: 71e428130186cb92c8fb2fc22ec26f2ce161a4ce36be071db6ecdd35a0eb52e6

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module CucumberAnalytics

  # A class modeling a Tag.

  class Tag

    include Raw
    include Sourceable
    include Nested


    # The name of the Tag
    attr_accessor :name


    # Creates a new Tag object and, if *source* is provided, populates the
    # object.
    def initialize(source = nil)
      parsed_tag = process_source(source)

      build_tag(parsed_tag) if parsed_tag
    end

    # Returns gherkin representation of the tag.
    def to_s
      name || ''
    end


    private


    def process_source(source)
      case
        when source.is_a?(String)
          parse_tag(source)
        else
          source
      end
    end

    def parse_tag(source_text)
      base_file_string = "\nFeature: Fake feature to parse"
      source_text = source_text + base_file_string

      parsed_file = Parsing::parse_text(source_text)

      parsed_file.first['tags'].first
    end

    def build_tag(parsed_tag)
      populate_name(parsed_tag)
      populate_raw_element(parsed_tag)
      populate_element_source_line(parsed_tag)
    end

    def populate_name(parsed_tag)
      @name = parsed_tag['name']
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cucumber_analytics-1.6.0 lib/cucumber_analytics/tag.rb
cucumber_analytics-1.5.2 lib/cucumber_analytics/tag.rb
cucumber_analytics-1.5.1 lib/cucumber_analytics/tag.rb
cucumber_analytics-1.5.0 lib/cucumber_analytics/tag.rb