Class: Metanorma::Release::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/release/channel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audience:, category:) ⇒ Channel

Returns a new instance of Channel.



33
34
35
36
37
# File 'lib/metanorma/release/channel.rb', line 33

def initialize(audience:, category:)
  @audience = audience
  @category = category
  freeze
end

Instance Attribute Details

#audienceObject (readonly)

Returns the value of attribute audience.



31
32
33
# File 'lib/metanorma/release/channel.rb', line 31

def audience
  @audience
end

#categoryObject (readonly)

Returns the value of attribute category.



31
32
33
# File 'lib/metanorma/release/channel.rb', line 31

def category
  @category
end

Class Method Details

.internal(category) ⇒ Object



27
28
29
# File 'lib/metanorma/release/channel.rb', line 27

def self.internal(category)
  new(audience: ChannelAudience::INTERNAL, category: category)
end

.members(category) ⇒ Object



23
24
25
# File 'lib/metanorma/release/channel.rb', line 23

def self.members(category)
  new(audience: ChannelAudience::MEMBERS, category: category)
end

.parse(channel_string) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/metanorma/release/channel.rb', line 6

def self.parse(channel_string)
  parts = channel_string.to_s.strip.split('/', 2)
  if ChannelAudience.values.include?(parts[0])
    new(audience: parts[0], category: parts[1] || 'default')
  else
    new(audience: ChannelAudience::PUBLIC, category: parts[0])
  end
end

.parse_list(strings) ⇒ Object



15
16
17
# File 'lib/metanorma/release/channel.rb', line 15

def self.parse_list(strings)
  (strings || []).map { |s| parse(s) }
end

.public(category) ⇒ Object



19
20
21
# File 'lib/metanorma/release/channel.rb', line 19

def self.public(category)
  new(audience: ChannelAudience::PUBLIC, category: category)
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/metanorma/release/channel.rb', line 55

def eql?(other)
  other.is_a?(self.class) && audience == other.audience && category == other.category
end

#hashObject



59
60
61
# File 'lib/metanorma/release/channel.rb', line 59

def hash
  [audience, category].hash
end

#matches?(filter_channels) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/metanorma/release/channel.rb', line 51

def matches?(filter_channels)
  filter_channels.any? { |c| eql?(Channel.parse(c)) }
end

#members?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/metanorma/release/channel.rb', line 47

def members?
  audience == ChannelAudience::MEMBERS
end

#public?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/metanorma/release/channel.rb', line 43

def public?
  audience == ChannelAudience::PUBLIC
end

#to_sObject



39
40
41
# File 'lib/metanorma/release/channel.rb', line 39

def to_s
  "#{audience}/#{category}"
end