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.6"

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
# File 'lib/officex2str.rb', line 19

def initialize(file_path)
  @path = file_path
  @content_type = MIME::Types.type_for(path).first.content_type
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

#pathObject

Returns the value of attribute path.



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

def path
  @path
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



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

def convert
  if valid_file?
    archives   = Zip::Archive.open(path) { |archive| archive.map(&:name) }
    pages      = pickup_pages(archives)
    xmls       = extract_xmls(pages)
    xml_to_str(xmls)
  else
    raise InvalidFileTypeError, "Not recognized file type"
  end
end