Class: Html2rss::AutoSource::Segment

Inherits:
Data
  • Object
show all
Defined in:
lib/html2rss/auto_source/segment.rb

Overview

One candidate content block discovered by Segmenter.

Constant Summary collapse

STRATEGIES =

Allowed Segmenter strategies.

%i[semantic list cluster].to_set.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#positionObject (readonly)

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



7
8
9
# File 'lib/html2rss/auto_source/segment.rb', line 7

def position
  @position
end

Returns the value of attribute primary_link

Returns:

  • (Object)

    the current value of primary_link



7
8
9
# File 'lib/html2rss/auto_source/segment.rb', line 7

def primary_link
  @primary_link
end

#root_nodeObject (readonly)

Returns the value of attribute root_node

Returns:

  • (Object)

    the current value of root_node



7
8
9
# File 'lib/html2rss/auto_source/segment.rb', line 7

def root_node
  @root_node
end

#strategyObject (readonly)

Returns the value of attribute strategy

Returns:

  • (Object)

    the current value of strategy



7
8
9
# File 'lib/html2rss/auto_source/segment.rb', line 7

def strategy
  @strategy
end

Class Method Details

.build(root_node:, strategy:, position:, primary_link: nil) ⇒ Segment

Parameters:

  • root_node (SST::Node)
  • primary_link (SST::Node, nil) (defaults to: nil)
  • strategy (Symbol)
  • position (Integer)

Returns:

Raises:

  • (ArgumentError)

    on invalid construction



15
16
17
18
19
20
21
22
23
24
# File 'lib/html2rss/auto_source/segment.rb', line 15

def self.build(root_node:, strategy:, position:, primary_link: nil)
  raise ArgumentError, 'root_node must be SST::Node' unless root_node.is_a?(SST::Node)
  unless primary_link.nil? || primary_link.is_a?(SST::Node)
    raise ArgumentError, 'primary_link must be SST::Node or nil'
  end
  raise ArgumentError, "unknown strategy: #{strategy.inspect}" unless Segment::STRATEGIES.include?(strategy)
  raise ArgumentError, 'position must be Integer' unless position.is_a?(Integer)

  new(root_node:, primary_link:, strategy:, position:)
end