Class: NicInfo::Notices
- Inherits:
-
Object
- Object
- NicInfo::Notices
- Defined in:
- lib/nicinfo/notices.rb
Overview
deals with RDAP notices structures
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #display_notices(json_response, ignore_excessive) ⇒ Object
- #display_single_notice(notice) ⇒ Object
-
#initialize(config) ⇒ Notices
constructor
A new instance of Notices.
- #is_excessive_notice(notices) ⇒ Object
Constructor Details
#initialize(config) ⇒ Notices
Returns a new instance of Notices.
26 27 28 |
# File 'lib/nicinfo/notices.rb', line 26 def initialize( config ) @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
24 25 26 |
# File 'lib/nicinfo/notices.rb', line 24 def config @config end |
Instance Method Details
#display_notices(json_response, ignore_excessive) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nicinfo/notices.rb', line 49 def display_notices json_response, ignore_excessive notices = json_response[ "notices" ] return if notices == nil if (is_excessive_notice(notices) ) && (@config.logger.data_amount != NicInfo::DataAmount::EXTRA_DATA) && !ignore_excessive @config.logger.start_data_item @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Excessive Notices", NicInfo::AttentionType::INFO @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "-----------------", NicInfo::AttentionType::INFO @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Response contains excessive notices.", NicInfo::AttentionType::INFO @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Use the \"-V\" or \"--data extra\" options to see them.", NicInfo::AttentionType::INFO @config.logger.end_data_item else notices.each do |notice| display_single_notice notice end end end |
#display_single_notice(notice) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/nicinfo/notices.rb', line 68 def display_single_notice notice @config.logger.start_data_item title = notice[ "title" ] if title == nil title = "" end @config.conf_msgs << "'title' in 'notice' is not a string." unless title.instance_of?( String ) @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "[ NOTICE ]", title, NicInfo::AttentionType::SECONDARY type = notice[ "type" ] if type != nil @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "Type", NicInfo.capitalize( type ), NicInfo::AttentionType::SECONDARY end description = notice[ "description" ] i = 1 if description.instance_of?( Array ) description.each do |line| if line.instance_of?( String ) @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, i.to_s, line, NicInfo::AttentionType::SECONDARY i = i + 1 else @config.conf_msgs << "eleemnt of 'description' in 'notice' is not a string." end end else @config.conf_msgs << "'description' in 'notice' is not an array." end links = notice[ "links" ] if links if links.instance_of?( Array ) alternate = NicInfo.get_alternate_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "More", alternate, NicInfo::AttentionType::SECONDARY if alternate about = NicInfo.get_about_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "About", about, NicInfo::AttentionType::SECONDARY if about tos = NicInfo.get_tos_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "TOS", tos, NicInfo::AttentionType::SECONDARY if tos copyright = NicInfo.get_copyright_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "(C)", copyright, NicInfo::AttentionType::SECONDARY if copyright license = NicInfo.get_license_link links @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "License", license, NicInfo::AttentionType::SECONDARY if license else @config.conf_msgs << "'links' is not an array." end end @config.logger.end_data_item end |
#is_excessive_notice(notices) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nicinfo/notices.rb', line 30 def is_excessive_notice notices return false if !notices return false if notices.length == 0 return true if notices.length > 2 word_count = 0 line_count = 0 notices.each do |notice| descriptions = NicInfo::get_descriptions notice, @config descriptions.each do |line| line_count = line_count + 1 word_count = word_count + line.length end if descriptions and descriptions.instance_of? Array end return true if line_count > 10 return true if word_count > 700 #otherwise return false end |