Class: ContentData::ContentInstance

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checksum, size, server_name, device, full_path, modification_time, content_instance_serializer = nil) ⇒ ContentInstance

Returns a new instance of ContentInstance.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
# File 'lib/content_data/content_data.rb', line 52

def initialize(checksum, size, server_name, device, full_path, modification_time, content_instance_serializer = nil)
  if content_instance_serializer != nil
    if (content_instance_serializer.checksum == nil)
      raise ArgumentError.new("checksum have to be defined")
    else
      @checksum = content_instance_serializer.checksum
    end
    if (content_instance_serializer.size == nil)
      raise ArgumentError.new("size have to be defined")
    else
      @size = content_instance_serializer.size
    end
    if (content_instance_serializer.modification_time == nil)
      raise ArgumentError.new("modification_time have to be defined")
    else
      @modification_time = ContentData.parse_time(content_instance_serializer.modification_time)
    end
    if (content_instance_serializer.server_name == nil)
      raise ArgumentError.new("server_name have to be defined")
    else
      @server_name = content_instance_serializer.server_name
    end
    if (content_instance_serializer.device == nil)
      raise ArgumentError.new("device have to be defined")
    else
      @device = content_instance_serializer.device
    end
    if (content_instance_serializer.full_path == nil)
      raise ArgumentError.new("full_path have to be defined")
    else
      @full_path = content_instance_serializer.full_path
    end
  else
    @checksum = checksum
    @size = size
    @server_name = server_name
    @device = device
    @full_path = full_path
    @modification_time = modification_time
  end
end

Instance Attribute Details

#checksumObject (readonly)

Returns the value of attribute checksum.



50
51
52
# File 'lib/content_data/content_data.rb', line 50

def checksum
  @checksum
end

#deviceObject (readonly)

Returns the value of attribute device.



50
51
52
# File 'lib/content_data/content_data.rb', line 50

def device
  @device
end

#full_pathObject (readonly)

Returns the value of attribute full_path.



50
51
52
# File 'lib/content_data/content_data.rb', line 50

def full_path
  @full_path
end

#modification_timeObject (readonly)

Returns the value of attribute modification_time.



50
51
52
# File 'lib/content_data/content_data.rb', line 50

def modification_time
  @modification_time
end

#server_nameObject (readonly)

Returns the value of attribute server_name.



50
51
52
# File 'lib/content_data/content_data.rb', line 50

def server_name
  @server_name
end

#sizeObject (readonly)

Returns the value of attribute size.



50
51
52
# File 'lib/content_data/content_data.rb', line 50

def size
  @size
end

Class Method Details

.instance_global_path(server_name, full_path) ⇒ Object



98
99
100
# File 'lib/content_data/content_data.rb', line 98

def ContentInstance.instance_global_path(server_name, full_path)
  "%s:%s" % [server_name, full_path]
end

Instance Method Details

#==(other) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/content_data/content_data.rb', line 107

def ==(other)
  return (self.checksum.eql? other.checksum and
      self.size.eql? other.size and
      self.server_name.eql? other.server_name and
      self.device.eql? other.device and
      self.full_path.eql? other.full_path and
      self.modification_time.to_i.eql? other.modification_time.to_i)
end

#global_pathObject



94
95
96
# File 'lib/content_data/content_data.rb', line 94

def global_path
  ContentInstance.instance_global_path(@server_name, @full_path)
end

#to_sObject



102
103
104
105
# File 'lib/content_data/content_data.rb', line 102

def to_s
  "%s,%d,%s,%s,%s,%s" % [@checksum, @size, @server_name,
                         @device, @full_path, ContentData.format_time(@modification_time)]
end