Class: Officex2str

Inherits:
Object
  • Object
show all
Defined in:
lib/officex2str.rb,
lib/officex2str/version.rb

Defined Under Namespace

Classes: InvalidFileTypeError

Constant Summary collapse

DOCX_CONTENT_TYPE =
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
XLSX_CONTENT_TYPE =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
PPTX_CONTENT_TYPE =
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
VALID_CONTENT_TYPE =
[DOCX_CONTENT_TYPE, XLSX_CONTENT_TYPE, PPTX_CONTENT_TYPE].freeze
VERSION =
"0.0.9"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Officex2str

Returns a new instance of Officex2str.



19
20
21
22
23
24
# File 'lib/officex2str.rb', line 19

def initialize(file_path)
  @path = file_path
  @content_type = MIME::Types.type_for(path).first.content_type
  @entries = valid_file? ? Zip::File.open(path).entries : []
  @xmls = []
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



13
14
15
# File 'lib/officex2str.rb', line 13

def content_type
  @content_type
end

#entriesObject

Returns the value of attribute entries.



13
14
15
# File 'lib/officex2str.rb', line 13

def entries
  @entries
end

#pathObject

Returns the value of attribute path.



13
14
15
# File 'lib/officex2str.rb', line 13

def path
  @path
end

#xmlsObject

Returns the value of attribute xmls.



13
14
15
# File 'lib/officex2str.rb', line 13

def xmls
  @xmls
end

Class Method Details

.convert(file_path) ⇒ Object



15
16
17
# File 'lib/officex2str.rb', line 15

def self.convert(file_path)
  self.new(file_path).convert
end

Instance Method Details

#convertObject



26
27
28
29
30
31
32
33
# File 'lib/officex2str.rb', line 26

def convert
  if valid_file?
    extract_xmls
    xml_to_str
  else
    raise InvalidFileTypeError, "Not recognized file type"
  end
end