Documentation
¶
Overview ¶
Package describe provides a implementation that parse a gcode file to recompile staticts and metrics.
Index ¶
- type Configurer
- type Description
- func (d *Description) BlocksCount() int
- func (d *Description) Filename() string
- func (d *Description) FormatJSON() (string, error)
- func (d *Description) FormatTemplate(template string) (string, error)
- func (d *Description) FormatYAML() (string, error)
- func (d *Description) LinesCount() int
- func (d *Description) Parse() error
- type Descriptionable
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configurer ¶
type Configurer interface {
// SetSource allows set the source content to get the metadatas.
SetSource(source io.Reader) error
// SetFilename allows set the file path to the source content.
SetFilename(filename string) error
}
Configurer is a interface that contains all functions that allows configure a new Description instance.
type Description ¶
type Description struct {
// contains filtered or unexported fields
}
Description implements Descriptionable interface
func New ¶
func New(options ...func(Configurer) error) (*Description, error)
New creates a instance of Description with all statics and metrics parsed from a gcode file.
It recives a list of configurations callbacks to set a io.Reader instance as the source of gcode file.
An error is returned if something was wrong while try initialize the Description instance.
func (*Description) BlocksCount ¶
func (d *Description) BlocksCount() int
BlocksCount implements Descriptionable.BlocksCount
Example ¶
package main
import (
"fmt"
"strings"
"github.com/mauroalderete/gcode-cli/description"
)
func main() {
source := strings.NewReader(`// this is a comment
N1 G0
N2 G1 X2
// another comment`)
// Creates a new instance of Description
desc, err := description.New(func(c description.Configurer) error {
// Configures the required source
c.SetSource(source)
return nil
})
if err != nil {
fmt.Printf("failed to prepare the file: %v", err)
return
}
// Executes the parsing
err = desc.Parse()
if err != nil {
fmt.Printf("some was wrong to try parse the source: %v", err)
}
// Shows the count of blocks
fmt.Printf("the source contains %d blocks", desc.BlocksCount())
}
Output: the source contains 2 blocks
func (*Description) Filename ¶
func (d *Description) Filename() string
Filename implements Descriptionable.Filename
Example ¶
package main
import (
"bufio"
"fmt"
"github.com/mauroalderete/gcode-cli/description"
)
func main() {
file := "some_printable_object.gcode"
// Creates a new instance of Description
desc, err := description.New(func(c description.Configurer) error {
// Configures the filename to will load
c.SetFilename(file)
// Configures the required source
c.SetSource(bufio.NewReader(nil))
return nil
})
if err != nil {
fmt.Printf("failed to prepare the file: %v", err)
return
}
// Checks if the filename configured match with expected
if desc.Filename() == file {
fmt.Printf("file loaded")
} else {
fmt.Printf("file missing")
}
}
Output: file loaded
func (*Description) FormatJSON ¶
func (d *Description) FormatJSON() (string, error)
FormatJSON implements Descriptionable.FormatJSON
func (*Description) FormatTemplate ¶
func (d *Description) FormatTemplate(template string) (string, error)
FormatTemplate implements Descriptionable.FormatTemplate
func (*Description) FormatYAML ¶
func (d *Description) FormatYAML() (string, error)
FormatYAML implements Descriptionable.FormatYAML
func (*Description) LinesCount ¶
func (d *Description) LinesCount() int
LinesCount implements Descriptionable.LinesCount
Example ¶
package main
import (
"fmt"
"strings"
"github.com/mauroalderete/gcode-cli/description"
)
func main() {
source := strings.NewReader(`// this is a comment
N1 G0
N2 G1 X2
// another comment`)
// Creates a new instance of Description
desc, err := description.New(func(c description.Configurer) error {
// Configures the required source
c.SetSource(source)
return nil
})
if err != nil {
fmt.Printf("failed to prepare the file: %v", err)
return
}
// Executes the parsing
err = desc.Parse()
if err != nil {
fmt.Printf("some was wrong to try parse the source: %v", err)
}
// Shows the count of lines
fmt.Printf("the source contains %d lines", desc.LinesCount())
}
Output: the source contains 4 lines
func (*Description) Parse ¶
func (d *Description) Parse() error
Parse implements Descriptionable.Parse
Example ¶
package main
import (
"fmt"
"strings"
"github.com/mauroalderete/gcode-cli/description"
)
func main() {
source := strings.NewReader(`// this is a comment
N1 G0
N2 G1 X2
// another comment`)
// Creates a new instance of Description
desc, err := description.New(func(c description.Configurer) error {
// Configures the required source
c.SetSource(source)
return nil
})
if err != nil {
fmt.Printf("failed to prepare the file: %v", err)
return
}
// Executes the parsing
err = desc.Parse()
if err != nil {
fmt.Printf("some was wrong to try parse the source: %v", err)
}
fmt.Printf("the source parsed succefull")
}
Output: the source parsed succefull
type Descriptionable ¶
type Descriptionable interface {
// Filename returns the filename of the gcode file input
// or a string empty if the input from stdin.
Filename() string
// LinesCount return the number of lines contains in input,
// this includes comments.
LinesCount() int
// BlocksCount returns the number of lines that are a gcode block valid.
BlocksCount() int
// Parse evaluates the gcode file stored to fill the internal fields.
Parse() error
// FormatJSON returns the Descriptionable instance value in YAML format or an error trying to do it.
FormatJSON() (string, error)
// FormatYAML returns the Descriptionable instance value in YAML format or an error trying to do it.
FormatYAML() (string, error)
// FormatTemplate returns the Descriptionable instance value using a Go template format or an error trying to do it.
FormatTemplate(template string) (string, error)
}
Descriptionable is a main interface to handle a Description of a gcode file