Class: NicInfo::Notices

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

Overview

deals with RDAP notices structures

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Notices

Returns a new instance of Notices.



27
28
29
30
# File 'lib/nicinfo/notices.rb', line 27

def initialize( config )
  @config = config
  @common = CommonJson.new( config )
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



25
26
27
# File 'lib/nicinfo/notices.rb', line 25

def config
  @config
end

Instance Method Details

#display_notices(json_response, ignore_excessive) ⇒ Object



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

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



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
# File 'lib/nicinfo/notices.rb', line 70

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" ]
  @common.display_simple_links( links )
  @config.logger.end_data_item
end

#is_excessive_notice(notices) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nicinfo/notices.rb', line 32

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