Class: Condenser::Export

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, input = {}) ⇒ Export

Returns a new instance of Export.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/condenser/export.rb', line 8

def initialize(env, input={})
  @environment = env
  
  @source = input[:source]
  @sourcemap = input[:map]
  @filename = input[:filename]
  @content_types = input[:content_types]
  @digest = input[:digest]
  @digest_name = input[:digest_name]
  @etag = input[:etag]
  @type = input[:type]
end

Instance Attribute Details

#content_typesObject (readonly)

Returns the value of attribute content_types.



6
7
8
# File 'lib/condenser/export.rb', line 6

def content_types
  @content_types
end

#digestObject (readonly)

Returns the value of attribute digest.



6
7
8
# File 'lib/condenser/export.rb', line 6

def digest
  @digest
end

#digest_nameObject (readonly)

Returns the value of attribute digest_name.



6
7
8
# File 'lib/condenser/export.rb', line 6

def digest_name
  @digest_name
end

#etagObject (readonly)

Returns the value of attribute etag.



6
7
8
# File 'lib/condenser/export.rb', line 6

def etag
  @etag
end

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/condenser/export.rb', line 6

def filename
  @filename
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/condenser/export.rb', line 6

def source
  @source
end

#sourcemapObject (readonly)

Returns the value of attribute sourcemap.



6
7
8
# File 'lib/condenser/export.rb', line 6

def sourcemap
  @sourcemap
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/condenser/export.rb', line 6

def type
  @type
end

Instance Method Details

#charsetObject



42
43
44
# File 'lib/condenser/export.rb', line 42

def charset
  @source.encoding.name.downcase
end

#content_typeObject



25
26
27
# File 'lib/condenser/export.rb', line 25

def content_type
  @content_types.last
end

#extObject



78
79
80
# File 'lib/condenser/export.rb', line 78

def ext
  File.extname(filename)
end

#hexdigestObject

Public: Returns String hexdigest of source.



47
48
49
# File 'lib/condenser/export.rb', line 47

def hexdigest
  @digest.unpack('H*'.freeze).first
end

#integrityObject



51
52
53
# File 'lib/condenser/export.rb', line 51

def integrity
  "#{@digest_name}-#{[@digest].pack('m0')}"
end

#lengthObject Also known as: size



33
34
35
# File 'lib/condenser/export.rb', line 33

def length
  @source.bytesize
end

#pathObject



21
22
23
# File 'lib/condenser/export.rb', line 21

def path
  filename.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" }
end

#to_jsonObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/condenser/export.rb', line 55

def to_json
  {
    path: path,
    etag: etag,
    type: type,
    size: size,
    digest: hexdigest,
    integrity: integrity
  }
end

#to_sObject



29
30
31
# File 'lib/condenser/export.rb', line 29

def to_s
  @source
end

#write(output_directory) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/condenser/export.rb', line 66

def write(output_directory)
  files = @environment.writers_for_mime_type(content_type).map do |writer|
    if writer.exist?(self)
      @environment.logger.debug "Skipping #{ self.path }, already exists"
    else
      @environment.logger.info "Writing #{ self.path }"
      writer.call(output_directory, self)
    end
  end
  files.flatten.compact
end