Class: SelfSDK::Sources
- Inherits:
-
Object
- Object
- SelfSDK::Sources
- Defined in:
- lib/sources.rb
Instance Method Summary collapse
-
#initialize(sources_file) ⇒ Sources
constructor
A new instance of Sources.
- #message_type(s) ⇒ Object
- #normalize_fact_name!(fact) ⇒ Object
- #normalize_operator!(input) ⇒ Object
- #validate_source!(source) ⇒ Object
Constructor Details
#initialize(sources_file) ⇒ Sources
Returns a new instance of Sources.
10 11 12 13 14 15 16 |
# File 'lib/sources.rb', line 10 def initialize(sources_file) @sources = SOURCE_DATA["sources"] @facts = [] @sources.each do |source, facts| @facts.push(*facts) end end |
Instance Method Details
#message_type(s) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sources.rb', line 40 def (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, } raise "invalid message type '#{s}'" unless types.key? s return types[s] end |
#normalize_fact_name!(fact) ⇒ Object
18 19 20 21 22 |
# File 'lib/sources.rb', line 18 def normalize_fact_name!(fact) fact = fact.to_s raise "invalid fact '#{fact}'" unless @facts.include?(fact) fact end |
#normalize_operator!(input) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sources.rb', line 28 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 |
#validate_source!(source) ⇒ Object
24 25 26 |
# File 'lib/sources.rb', line 24 def validate_source!(source) raise "invalid source '#{source}'" unless @sources.keys.include?(source.to_s) end |