Class: SelfSDK::Sources

Inherits:
Object
  • Object
show all
Defined in:
lib/sources.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources_file) ⇒ Sources

Returns a new instance of Sources.



12
13
14
15
16
17
18
# File 'lib/sources.rb', line 12

def initialize(sources_file)
  @sources = SOURCE_DATA["sources"]
  @facts = []
  @sources.each do |source, facts|
    @facts.push(*facts)
  end
end

Instance Attribute Details

#factsObject (readonly)

Returns the value of attribute facts.



10
11
12
# File 'lib/sources.rb', line 10

def facts
  @facts
end

#sourcesObject (readonly)

Returns the value of attribute sources.



10
11
12
# File 'lib/sources.rb', line 10

def sources
  @sources
end

Instance Method Details

#core_fact?(fact) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/sources.rb', line 44

def core_fact?(fact)
  @facts.include? fact.to_s
end

#message_type(s) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sources.rb', line 48

def message_type(s)
  types = { fact_request: SelfSDK::Messages::FactRequest::MSG_TYPE,
            fact_response: SelfSDK::Messages::FactResponse::MSG_TYPE,
            chat_message: SelfSDK::Messages::ChatMessage::MSG_TYPE,
            chat_message_deivered: SelfSDK::Messages::ChatMessageDelivered::MSG_TYPE,
            chat_message_read: SelfSDK::Messages::ChatMessageRead::MSG_TYPE,
            chat_invite: SelfSDK::Messages::ChatInvite::MSG_TYPE,
            chat_join: SelfSDK::Messages::ChatJoin::MSG_TYPE,
            chat_remove: SelfSDK::Messages::ChatRemove::MSG_TYPE,
            document_sign_response: SelfSDK::Messages::DocumentSignResponse::MSG_TYPE,
            connection_response: SelfSDK::Messages::ConnectionResponse::MSG_TYPE,
            voice_setup: SelfSDK::Messages::VoiceSetup::MSG_TYPE,
            voice_start: SelfSDK::Messages::VoiceStart::MSG_TYPE,
            voice_accept: SelfSDK::Messages::VoiceAccept::MSG_TYPE,
            voice_busy: SelfSDK::Messages::VoiceBusy::MSG_TYPE,
            voice_stop: SelfSDK::Messages::VoiceStop::MSG_TYPE,
            voice_summary: SelfSDK::Messages::VoiceSummary::MSG_TYPE,
           }
  raise "invalid message type '#{s}'" unless types.key? s
  return types[s]
end

#normalize_fact_name(fact) ⇒ Object



20
21
22
# File 'lib/sources.rb', line 20

def normalize_fact_name(fact)
  fact.to_s
end

#normalize_operator!(input) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sources.rb', line 32

def normalize_operator!(input)
  return "" unless input

  operators = { equals: '==',
                different: '!=',
                great_or_equal_than: '>=',
                less_or_equal: '<=',
                great_than: '>',
                less_than: '<' }
  get(operators, input, "operator")
end

#normalize_source(source) ⇒ Object



24
25
26
# File 'lib/sources.rb', line 24

def normalize_source(source)
  source.to_s
end

#validate_source!(source) ⇒ Object



28
29
30
# File 'lib/sources.rb', line 28

def validate_source!(source)
  raise "invalid source '#{source}'" unless @sources.keys.include?(source.to_s)
end