Class: Bizside::StringIO

Inherits:
StringIO
  • Object
show all
Defined in:
lib/bizside/string_io.rb

Direct Known Subclasses

CarrierwaveStringIO

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = '', mode = 'r+') ⇒ StringIO

Returns a new instance of StringIO.



9
10
11
12
13
14
15
16
17
18
# File 'lib/bizside/string_io.rb', line 9

def initialize(string = '', mode = 'r+')
  super(string, mode)
  begin
    self.md5 = Digest::MD5.hexdigest(self.read)
  rescue
    #失敗しても何もしない。
  ensure
    self.rewind
  end
end

Instance Attribute Details

#base_dirObject

Returns the value of attribute base_dir.



3
4
5
# File 'lib/bizside/string_io.rb', line 3

def base_dir
  @base_dir
end

#content_typeObject

Returns the value of attribute content_type.



5
6
7
# File 'lib/bizside/string_io.rb', line 5

def content_type
  @content_type
end

#file_sizeObject

Returns the value of attribute file_size.



6
7
8
# File 'lib/bizside/string_io.rb', line 6

def file_size
  @file_size
end

#fullpathObject

Returns the value of attribute fullpath.



4
5
6
# File 'lib/bizside/string_io.rb', line 4

def fullpath
  @fullpath
end

#md5Object

Returns the value of attribute md5.



7
8
9
# File 'lib/bizside/string_io.rb', line 7

def md5
  @md5
end

Instance Method Details

#original_dirnameObject



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

def original_dirname
  fullpath ? File.dirname(fullpath) : ''
end

#original_filenameObject



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

def original_filename
  fullpath ? File.basename(fullpath) : ''
end

#relative_dirnameObject



28
29
30
31
32
33
34
35
# File 'lib/bizside/string_io.rb', line 28

def relative_dirname
  if fullpath
    relpath = fullpath.sub(/^#{Regexp.quote(base_dir)}/,'').sub(/^\//,'')
    File.dirname(relpath) == '.' ? '' : File.dirname(relpath)
  else
    ''
  end
end